谷歌搜索这个问题后,我设法做到这一点
- (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;
}
这段代码我设置了文本字段“ txtStudentMark”的委托,并设置了它的标签...
-(void) textFieldDidEndEditing: (UITextField * ) textField
{
NSString *text = [(UITextField *)[self.view viewWithTag:55] text];
NSLog(@"%@",text);
}
我不断使用NSLog函数获取空值
我在自定义单元格中有一个textField,用户将在其中填充数据,我需要从所有textfield中获取所有数据,我的方法正确吗?
据我了解,我需要为textField设置标签并将其设置为委托,然后我可以通过tag调用textfield来获取其中的文本。
我该如何进行这项工作?
你为什么不使用
-(void) textFieldDidEndEditing: (UITextField * ) textField
{
NSString *text = [textField text];
NSLog(@"%@",text);
}
?
您的问题是您正在将文本字段添加到单元格中,但是向视图询问此标记。
编辑:
从表视图获取文本字段
-(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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句