custom searchResultsTableView
I am looking to have custom UITableViewCells
for my UISearchDisplayController
. The searchResultsTableView
is a readonly property. I have the delegate and datasource for the searchviewcontroller returning the custom cells, however, it see开发者_如何学Cms to still be using the searchResultsTableView
cells. What's the best way to have the search results using my own UITableViewCells
?
When a search begins, a whole new UITableView is created. This new table view will use default settings and won't match your table view. In your UISearchDisplayDelegate, override searchDisplayControllerWillBeginSearch: in order to re-theme the new UITableView, like this:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
// Re-style the search controller's table view
UITableView *tableView = controller.searchResultsTableView;
tableView.backgroundColor = [UIColor blueColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
I'm not sure I fully understand the question, but it sounds like you want two different UITableViewCell
types (subclasses?) to be returned when you're typing a search, or when you're not searching. Is that right?
Like John said, and depending on how you hooked up the UISearchDisplayController
, both the search results table view and your default table view will fire cellForRowAtIndexPath
and willDisplayCellForRowAtIndexPath
. In those methods you can check which tableView is asking for the cell and customize it as necessary. I customize the background, text and color of my cells and this approach works well for me. I can post code if you'd like.
精彩评论