在用户开始在SearchBar中输入之前,有没有办法在结果中预先填充UISearchDisplayController?

时间:2012-07-10 08:12:49

标签: iphone objective-c uisearchbar uisearchdisplaycontroller

我想在搜索栏变为活动状态后立即显示过去的搜索。但即使数据源具有这些值,搜索显示控制器也不会调用表视图方法,直到用户开始键入。有没有办法在UISearchDisplayController上强制执行此操作?

1 个答案:

答案 0 :(得分:-1)

只要您的代理设置正确,您就可以返回所需的任何数据集。

 self.searchResults = @[@"some stuff", @"some more stuff", @"and so on..."];

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
   if (tableView == [[self searchDisplayController] searchResultsTableView]) {
     return [self.searchResults count];
   }
   else {
     return [self.data count];
   }
}
相关问题