OGeek|极客世界-中国程序员成长平台

标题: ios - 如何从所有文本字段中获取所有值 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:41
标题: ios - 如何从所有文本字段中获取所有值

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

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)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;
}

此代码我设置文本字段“txtStudentMark”委托(delegate)并设置它的标签...

-(void) textFieldDidEndEditing: (UITextField * ) textField
{
    NSString *text = [(UITextField *)[self.view viewWithTag:55] text];
    NSLog(@"%@",text);
}

我使用 NSLog 函数不断得到空值

我在自定义单元格中有一个文本字段,用户将填充数据,我需要从所有文本字段中获取所有数据,我走对了吗?

据我了解,我需要为 textField 设置标签并将其设置为委托(delegate),然后我可以通过标签调用 textfield 以获取其中的文本。

我怎样才能完成这项工作?



Best Answer-推荐答案


你为什么不使用

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

您的问题是您将文本字段添加到单元格中,但要求查看此标签。

编辑:

从 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);
}

关于ios - 如何从所有文本字段中获取所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31142736/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4