【问题标题】:Cell at UISearchController SearchTableView not responding to didSelectRowAtIndexPathUISearchController SearchTableView 的单元格没有响应 didSelectRowAtIndexPath
【发布时间】:2013-04-03 21:34:21
【问题描述】:

我有一个带有搜索显示控制器的主表视图。我正在使用实现

的自定义 cell.h
  • (void)setSelected:(BOOL)选定动画:(BOOL)动画

当我从主表中选择单元格时,上面的代码会更改此选定单元格的背景颜色。当我选择从搜索栏中搜索时,搜索显示控制器使用

以正确的背景颜色显示所选单元格
  • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

但是,在搜索显示控制器上显示的该单元格不响应didSelectRowAtIndexPathdidDeselectRowAtIndexPath。另一方面,其他细胞对这两种方法都有反应。

我想要实现的是主表和搜索显示控制器上的搜索表视图之间的同步,其中选定的单元格应该在主表和搜索表视图中显示为选中状态,但允许选择和取消选择。

请指教。非常感谢。

【问题讨论】:

    标签: objective-c uitableview uisearchbar uisearchdisplaycontroller


    【解决方案1】:

    我找到了问题的答案:

    使用

    • (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView

    [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:[searchResult indexOfObject:currentFriend] inSection:0] 动画:NO scrollPosition:0];

    而不是

    (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多