在TagViewController.m中我将标签添加到cellview.xib的文本字段
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
TagCell *cell = (TagCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TagCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.txtCellTag.tag = indexPath.row;
return cell;
}
开启按钮点击我试图通过以下功能
获取textField的值(IBAction)btnSave:(id)sender {
for(int i=0;i<[dataId count];i++) {
UITableViewCell *cell = [[self tblImages] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
if(cell == nil) {
NSLog(@";Cell is nil"); // Cell is always nil
} else {
UITextField *textField = (UITextField *)[cell viewWithTag:i];
NSLog(@"Value is %@", textField.text);
}
}
}
我正在获得All Textfield EXCEPT First Row的价值 第一个字段值始终为NULL
答案 0 :(得分:0)
最好对UITableViewCell进行类型转换并从单元格中获取文本字段。
for(int i=0;i<[dataId count];i++) {
UITableViewCell *cell = (TagCell *)[[self tblImages] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
if(cell == nil) {
NSLog(@";Cell is nil"); // Cell is always nil
} else {
UITextField *textField = cell.txtCellTag;
NSLog(@"Value is %@", textField.text);
}
}