如何从所有文本字段中获取所有值
How to get all values from all textfields
在谷歌搜索这个问题后,我设法做到了
- (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 以获取其中的文本。
我怎样才能完成这项工作?
你为什么不用
-(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);
}
@Doro 感谢您的帮助。
既然问题已经解决了,这就是对我来说很有效的答案
通过TAG获取文本域中的行号和数据
-(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);
}
在谷歌搜索这个问题后,我设法做到了
- (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 以获取其中的文本。
我怎样才能完成这项工作?
你为什么不用
-(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);
}
@Doro 感谢您的帮助。
既然问题已经解决了,这就是对我来说很有效的答案
通过TAG获取文本域中的行号和数据
-(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);
}