Show UISearchDisplayTableView when search string is empty [duplicate]

两盒软妹~` 提交于 2019-12-04 06:45:36

I know this is an old post, but I had the same problem with the new iOS8 UISearchController. The workaround is to check if the string is empty and to set the result tableview's property HIDDEN = NO

Well the solution to this is to not use the UISearchDisplayController. It simply doesn't offer the flexibility you need to do something like this. Build your own custom search interface with a UISegmentedControl, UISearchBar and UITableView for maximum flexibility.

What you can do is When the user clicks on search and the string is empty change the searchBartext to "\n" carriage return

self.searchDisplayController.searchBar.text = @"\n";

The carriage return is not displayed in the searchbar an also it will not be the same string, as if the user types "\n". so it works fine. In the

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString 

method you can set the searchbar text back to @"". if the searchstring was @"\n"

self.searchDisplayController.searchBar.text = @"";

That's what worked for me!

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