Ios 未从UITableView单元格获取第一个UITextField的值

Ios 未从UITableView单元格获取第一个UITextField的值,ios,uitextfield,uitableview,Ios,Uitextfield,Uitableview,在TagViewController.m中,我从cellview.xib向文本字段添加标记 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableCell"; TagCell *cell = (TagCell *)[tab

在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);
        }
    }
}
(iAction)b保存:(id)发送方{

对于(int i=0;i最好对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);
    }
}

for(int i=0;iIs-the-row-off-screen?在单元格中存储状态不是一个好主意,因为它们在屏幕上和屏幕下移动时会被回收和丢弃。当用户输入值时,您应该将其传递给视图控制器。单元格和视图控制器之间的委托方法通常适用于这样的数据传递。