2

我想在 UITableViewCell(每行一个文本字段)中添加 12 个 UITextField,并使用它的标签访问每个 UITextField 的文本。我怎样才能做到这一点?

4

1 回答 1

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;
于 2012-05-17T13:52:36.803 回答