Ios 如何从所有文本字段中获取所有值

Ios 如何从所有文本字段中获取所有值,ios,objective-c,uitextfield,tableviewcell,Ios,Objective C,Uitextfield,Tableviewcell,在谷歌搜索了这个问题后,我设法做到了这一点 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"InsertMarksCell"; SaveAllExamMarksForAllStudentsTableViewCell *myCell = [tableView

在谷歌搜索了这个问题后,我设法做到了这一点

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NSString *cellIdentifier = @"InsertMarksCell";
    SaveAllExamMarksForAllStudentsTableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    StudentPersonalInfo *newStudentName = feedItemsNow[indexPath.row];

    myCell.txtStudentMark.text = @"hello";
    myCell.txtStudentMark.delegate = self;
    myCell.txtStudentMark.tag = indexPath.row;

    return myCell;
}
这段代码设置textfield“txtStudentMark”委托并设置它的标记

-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    NSString *text = [(UITextField *)[self.view viewWithTag:55] text];
    NSLog(@"%@",text);
}
我一直使用NSLog函数获取空值

我在自定义单元格中有一个文本字段,用户将用数据填充该字段,我需要从所有文本字段中获取所有数据,我的方法正确吗

据我所知,我需要为textField设置标记并将其设置为delegate,然后我可以逐个标记调用textField以获取其中的文本

我怎样才能做到这一点呢?

你为什么不使用

-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    NSString *text = [textField text];
    NSLog(@"%@",text);
} 
?

您的问题是您正在将textfield添加到单元格中,但请查看此标记

编辑:

从tableview获取文本字段的步骤

-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    UITableViewCell *cell = [self.view.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:55 inSection:0]];

    NSString *text = [(UITextField *)[cell.contentView viewWithTag:55] text];
    NSLog(@"%@",text);
}

@多罗谢谢你的帮助

既然问题解决了,这个答案对我来说很有效

通过标记获取文本字段中的行号和数据

-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    // here get the tag number which is the row number
    NSInteger *rowNumberWithout200 = (long)textField.tag;
    NSString  *myRow = [NSString stringWithFormat: @"%ld", rowNumberWithout200];
    NSLog(@"row %@",myRow);

    // get the text in the cell with the required tag...
    UITableViewCell* myCell = (UITableViewCell*)textField.superview;
    NSString *StudentMark = [(UITextField *)[myCell viewWithTag:textField.tag] text];
    NSLog(@"mark %@",StudentMark);
}

如果
text
nil
则表示
self.view
nil
,或者
self.view
没有标记为55的子视图。我的标记为55。。。我已经用“hello”填充了文本字段,只是编辑了代码并添加了它,所有的文本字段都有“hello”文本。textfield在@interface saveAllexamarksforAllStudentStableViewCell:UITableViewCell中声明。如何调用textfield?textfield是tableViewCell的子视图?对吗?很好,编辑完成后可以工作并打印所有值。。。但是,我可以通过标记调用textfield吗?UITableViewCell*cell=[self.view.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:55第0节];在“self.view.tableView”中,我无法将其设置为我的tableView self.view.studentsnamedmarkstableview错误:在对象类型上找不到属性studentsnamedmarkstableviewUIView@jack,仅通过tableview,因为textfield位于单元格的内容视图中。请参阅我的编辑。视图层次结构看起来像uitableview-uitableviewcell-contentview-your\u文本字段。我可能会错过一些临时的观点,但顺序和我一样mentioned@jack,使用自我。学生们用自己的方式来做标记。StudentsNamedMarkStableView,我得到空值,并且我将标记改为0而不是55,因为“indexath.row必须从0开始,所以我知道标记0将存在,但仍然是空值。。。