【问题标题】:How to add 12 text fields in a table view cell and access each text field's text by its tag value?如何在表格视图单元格中添加 12 个文本字段并通过其标记值访问每个文本字段的文本?
【发布时间】:2012-05-17 13:49:55
【问题描述】:

我想在 UITableViewCell 中添加 12 个 UITextFields(每行一个文本字段),并使用它的标签访问每个 UITextField 的文本。我该怎么做?

【问题讨论】:

标签: ios uitableview uitextfield


【解决方案1】:
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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    相关资源
    最近更新 更多