UITableViewCellStyleValue2 edit text - filling form like
I need to create a form so that the user can edit all cells of the table (about 20).
Can I do it with 开发者_开发技巧UITableViewCellStyleValue2? If so, how?
Or do I need to create a subclass of UITableViewCell?
In terms of arquitect, maybe it's better to create a subclass, but anyway, i'll need to edit the table, the textlabel.text property.
What's the best way? And how can I do it?
Thanks,
RL
I recommend adding your own views to the cell's contentView, like so:
- (UITableViewCell *)tableView:(UITableView *)tv
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell;
{
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor = [UIColor whiteColor];
UILabel *lbl = [[UILabel alloc] init];
lbl.frame = CGRectMake(3, 2, 160, tv.rowHeight - 4);
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor blackColor];
lbl.font = [UIFont boldSystemFontOfSize:16];
[cell.contentView addSubview:lbl];
[lbl release];
if(indexPath.row == 0)
{
lbl.text = @"Cell Name";
UITextField *textField;
textField = [[UITextField alloc] initWithFrame:CGRectMake(170,
tv.rowHeight / 2 - 10, 100, 20)];
textField.borderStyle = UITextBorderStyleNone;
textField.textColor = [UIColor blackColor];
textField.font = [UIFont systemFontOfSize:14];
textField.placeholder = @"Placeholder";
textField.backgroundColor = [UIColor clearColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.tag = indexPath.row;
textField.delegate = self;
[cell.contentView addSubview:textField];
[textField release];
}
...
[arp drain];
}
return [cell autorelease];
}
This is just a demonstration but you can see where you need to extend it to support additional cells, etc.
精彩评论