开发者

How to control the searchResultsTableView of a UISearchDisplayController?

I wonder how to take control over the table view that is used by the UISearchDisplayController. You can't overwrite the searchResultsTableView property of the UISearchDisplayController, because it is a read-only property.

I've tried to overlay the searchResultsTableView by a custom UITableView. That works just once, but as soon as you try a second search, the real searchResultsTableView is on top again. (I mean, you type in some text in the searchBar, your custom table view is on top and displays the search results, afterwards you press the cancel button. Now, if you repeat this, your custom table won't be displayed and the searchResultTableView of the UISearchDisplayController wil be on top).

Of course, you can try it without a UISearchDisplayContr开发者_StackOverflow中文版oller, but I count on the advantages of this class, I just want to customize the tableView.


You cannot set the searchResultsTableView, but you can manipulate it in the appropriate delegate method:

-(void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
   tableView.backgroundColor = self.tableView.backgroundColor;
   tableView.separatorColor = self.tableView.separatorColor;
       ...


You have a TableViewDataSource property on the UISearchDisplayController, this data source produces the UITableViewCell. Implement the UITableViewDataSource protocol and you'll have the control over the customization of the tableView in the method :

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜