How to control the searchResultsTableView of a UISearchDisplayController?

北战南征 提交于 2019-12-07 02:47:00

问题


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 UISearchDisplayController, but I count on the advantages of this class, I just want to customize the tableView.


回答1:


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




回答2:


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;
       ...


来源:https://stackoverflow.com/questions/2193094/how-to-control-the-searchresultstableview-of-a-uisearchdisplaycontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!