我想将单元格添加到UItableView中,就像在ipad上的mail.app中一样。在我的单元格中,我有UITextFields,我已经改变了这个方法来设置焦点
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath{
NSLog(@"%d",newIndexPath.row);
UITextField* field = (UITextField *) [tblView viewWithTag: newIndexPath.row];
int l_cellNum = field.tag;
if(l_cellNum == 1 && isAddedNewRow == FALSE){
isAddedNewRow = TRUE;
[cellsArray insertObject:@"CC" atIndex:1];
[cellsArray insertObject:@"BCC" atIndex:2];
CGRect tvbounds = [tblView bounds];
[tblView setBounds:CGRectMake(tvbounds.origin.x,
tvbounds.origin.y,
tvbounds.size.width,
tvbounds.size.height)];
NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0];
NSIndexPath *path2 = [NSIndexPath indexPathForRow:2 inSection:0];
NSArray *indexArray = [NSArray arrayWithObjects:path1,path2,nil];
[tblView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationTop];
[tblView reloadRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
[field becomeFirstResponder];
}
但是当我点击其中一个单元格时,我添加了2个单元格(如mail.app),但我的textFields标签没有更新,我无法设置焦点=(。如果我调用reloaddata方法调用 - cellForRowAtIndexPath在所有单元格的beggining和after之后有这个新单元格,它也不会工作。
答案 0 :(得分:1)
听起来你正在寻找的是一种内置的单元格样式UITableViewStyleSubtitle
,你可以像iPad Mail.app一样自定义字幕。请查看iOS documentation中的此页面。然后,您可以将UITableViewCell
的副标题设置为您需要的文本
此外,iOS文档提供了有关customizing table view cells的更多信息。