【发布时间】:2012-05-17 13:49:55
【问题描述】:
我想在 UITableViewCell 中添加 12 个 UITextFields(每行一个文本字段),并使用它的标签访问每个 UITextField 的文本。我该怎么做?
【问题讨论】:
标签: ios uitableview uitextfield
我想在 UITableViewCell 中添加 12 个 UITextFields(每行一个文本字段),并使用它的标签访问每个 UITextField 的文本。我该怎么做?
【问题讨论】:
标签: ios uitableview uitextfield
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;
【讨论】: