如何在表格视图单元格中添加12个文本字段,并按标记值访问每个文本字段的文本?

时间:2012-05-17 13:49:56

标签: ios uitableview uitextfield

我希望在UITableViewCell中添加12个UITextField(每行一个文本字段),并使用它的标记访问每个UITextField的文本。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

UITextField *textField = (UITextField *)[cell viewWithTag:1];
// 1 is your tag, and use textField.text to get the text in the textField.

您的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//...
nameLabel.tag =1; // 1 is your nameLabel's tag
[tv setDelegate:self];
tv.tag = indexPath.row + 1; // set it to tv.tag = indexPath.row + 2; because 1 is your nameLabel's tag

UITextField *textField = (UITextField *)[cell viewWithTag:tv.tag];//
NSLog(@"%@",textField.text);

return cell;