【问题标题】:Get cell's textLabel.text from a cell in UISearchDisplayController?从 UISearchDisplayController 中的单元格获取单元格 textLabel.text?
【发布时间】:2011-09-20 15:20:18
【问题描述】:

当我在 常规 tableView 中(在 didSelectRowAtIndexPath 方法中)获取单元格的 textLabel.text 时,我会这样做(并且有效!):

UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:indexPath];
NSLog(@"Cell's text: %@",cell.textLabel.text);

当我单击 UISearchDisplayController 中的单元格时,这不起作用。当我以该方法推送下一个视图控制器时,它将推送。但是对于 cell.textLabel.text,我总是得到“null”。

我做错了什么?

提前非常感谢!!!

【问题讨论】:

    标签: iphone ios uitableview nsstring


    【解决方案1】:

    在 iphonedevsdk.com 的帮助下,我发现这段代码有效:

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"Cell's text: %@",cell.textLabel.text);
    

    这是因为前面的代码所做的是,它是从视图控制器访问 tableView,而不是 UISearchDisplayController 的 tableView。此代码可以访问两个 tableView。

    :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多