我有一个UITableViewCells文本框的分组TableView。UITableViewCell中的UITextView - 标签问题
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.section < 6) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10,580, 31)];
textField.tag = indexPath.section + 22;
textField.delegate = self;
[cell.contentView addSubview:textField];
[textField release];
}
return cell;
}
因此,当我点击保存按钮,将saveItem方法被称为:
- (void)saveItem {
NSMutableArray *textFieldArray = [[NSMutableArray alloc] init];
for (int i = 0; i <6; i++) {
[textFieldArray addObject:(UITextField *)[self.view viewWithTag:22+i]];
}
...
}
我可以改变前4个TextField的值不会有问题。他们也被保存,但是当我改变在第五或第六文本字段的值,我的应用程序崩溃,我得到一个错误:
*终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因是:“* - [ NSMutableArray insertObject:atIndex:]:试图在0处插入nil对象'
有什么建议吗?
到目前为止感谢。
是否显示所有六个部分? – Nekto
是的,他们也充满了正确的价值观。 – jussi
如果您在创建新单元格时仅添加文本字段,那么此时您正在向可能已有单元格的单元格添加文本字段。 – jrturton