【问题标题】:How to find a cell textfield outside of a tableView delegate method?如何在 tableView 委托方法之外找到单元格文本字段?
【发布时间】:2016-01-04 17:16:15
【问题描述】:

我有一个带有文本字段的自定义 tableView 单元格。现在,我想识别 tableView 委托方法之外的 textField。我试过这个-

UIView *cell = textField;
[cell isKindOfClass:[UITableViewCell class]];

但它不起作用。

【问题讨论】:

  • 似乎您需要整个单元格,而不仅仅是文本字段。您需要为此提供更多上下文...
  • 如果它可能对您有用,请查看下面的链接stackoverflow.com/a/24246881/5184217

标签: objective-c uitableview storyboard ui-design


【解决方案1】:

要从表格视图中获取具体单元格,您需要知道该单元格的索引路径。然后你需要这样做:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];  //you should set your indexes of row and section instead of zeros
MyCustomCell *cell = [myTableView cellForRowAtIndexPath:indexPath];

现在,如果文本字段是您的自定义单元格的属性,您可以使用 cell.myTextField 获取它

例如:

UITextField *textField = cell.myTextField;

现在你可以用它做你想做的事了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 2022-01-08
    相关资源
    最近更新 更多