【发布时间】:2015-06-30 15:42:25
【问题描述】:
在谷歌搜索这个问题后,我设法做到了这一点
- (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 以获取其中的文本。
我怎样才能完成这项工作?
【问题讨论】:
-
如果
text是nil,那么这意味着self.view是nil,或者self.view没有标签为55 的子视图。 -
我有一个标签 55 ...我已经用 "hello" 填充了文本字段,只是编辑了代码并添加了它,所有文本字段都有 "hello" 文本。文本字段在@interface SaveAllExamMarksForAllStudentsTableViewCell 中声明: UITableViewCell 我如何调用文本字段?
-
textfield 是 tableViewCell 的子视图?对吗?
标签: ios objective-c uitextfield tableviewcell