2012-01-17 79 views
0

我想将单元格添加到UItableView中,就像在ipad上的mail.app中一样。在我的小区我有UITextFields,我必须改变这种方法将焦点设置将单元格添加到uitableView中像Mail.app

- (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),但我的文本框的标签不更新,我不能把重点放在它=(如果我打电话reloaddata方法它调用-cellForRowAtIndexPath与这个新细胞在开始和所有细胞之后,它不会工作太多。

回答

1

这听起来像你什么我们正在寻找的是一种名为UITableViewStyleSubtitle的内置单元格,您可以像iPad Mail.app一样自定义字幕。请看iOS documentation中的这一页。然后,您可以设置的字幕10到你需要的文字。
此外,iOS文档有关于customizing table view cells的更多信息。