我希望在UITableViewCell中添加12个UITextField(每行一个文本字段),并使用它的标记访问每个UITextField的文本。我怎么能这样做?
答案 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;