如何控制UISearchDisplayController的searchResultsTableView? [英] How to control the searchResultsTableView of a UISearchDisplayController?

查看:166
本文介绍了如何控制UISearchDisplayController的searchResultsTableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何控制 UISearchDisplayController 使用的表视图。您不能覆盖 UISearchDisplayController searchResultsTableView 属性,因为它是只读财产。



我试图通过自定义 UITableView searchResultsTableView $ C>。这只能工作一次,但只要你尝试第二次搜索,真正的 searchResultsTableView 就会再次出现。 (我的意思是,你在 searchBar 中输入一些文字,你的自定义表格视图在顶部并显示搜索结果,之后你按下取消按钮。现在,如果你重复此操作,您的自定义表将不会显示,并且UISearchDisplayController的 searchResultTableView 将位于顶部。)



当然,您可以在没有 UISearchDisplayController 的情况下尝试,但我依靠这个类的优点,我只想自定义 tableView

解决方案

你有一个 TableViewDataSource 属性 UISearchDisplayController ,此数据源生成 UITableViewCell 。实现 UITableViewDataSource 协议,您将可以控制方法中tableView的自定义:

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


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.

解决方案

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

这篇关于如何控制UISearchDisplayController的searchResultsTableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆