【问题标题】:UISearchDisplayController is not displaying any cellsUISearchDisplayController 不显示任何单元格
【发布时间】:2010-08-13 00:30:15
【问题描述】:

我有一个在 Interface Builder 中正确连接的 UISearchDisplayController。

delegate = Files Owner
searchBar = Search Bar
searchContentsController = Files Owner
searchResultsDataSource = Files Owner
searchResultsDelegate = Files Owner

当我的 UITableView 调用 numberoOfRowsInSection: 时,会返回正确的数字。

但是,我在cellForRowAtIndexPath: 中的单元格甚至无法到达:

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

 if (tblView == searchController.searchResultsTableView){
  NSLog(@"search will go here");
  UITableViewCell* cell = [self provideSearchQueryCells:tblView identifer:@"searchQueryCell"];
  STSymbol *aSymbol = [self.searchQueryResults objectAtIndex:indexPath.row];

  cell.textLabel.text = aSymbol.symbol;
  cell.detailTextLabel.text = aSymbol.symbol_title;

  return cell;
 }
 else { ... }

它总是进入 else 条件。

我不确定为什么。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uisearchbar uisearchdisplaycontroller


    【解决方案1】:

    我需要创建一个 UISearchDisplayController 的实例,而不是使用 self.searchDisplayController。

    【讨论】:

      【解决方案2】:

      使用以下内容。它应该可以工作。

       if ([tblView isEqual:[searchController searchResultsTableView]]) {
      ...
      }
      

      您还应该确保搜索结果的行数正确,如下所示:

      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
      {
      
          if ([tblView isEqual:[searchController searchResultsTableView]]) {
              return [self.searchResults count];
          }
      ...
      }
      

      【讨论】:

        【解决方案3】:

        这是对代码的近距离猜测,但我们是否正在查看搜索显示控制器本身?也许你的self.searchDisplayController.searchResultsTableView 应该只是self.searchResultsTableView。

        如果不了解您的代表,我无法确定。

        【讨论】:

        • 我相信是这样,因为这段代码在 UITableViewController 子类中。 self.searchResultsTableView 不是 UITableViewController 中的属性。
        • 我已经修改了我的帖子,以展示代表们在 IB 中的联系方式。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-01
        相关资源
        最近更新 更多