Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchDisplayController - how to display search result with only by scope button selected but empty search string

The UISearchDisplayController is very handy and implementing search is pretty straightforward.

However, I bump into problem when, in my app, I want to display search result with empty search string but selected scope button.

It seems like it's a must to enter some search string in order to get the search result table being initialized and displayed.

Is there any ways to display search result immediately after user has picked a scope but not entered search word yet?

Thanks Bill

like image 967
billibala Avatar asked Apr 26 '10 04:04

billibala


Video Answer


2 Answers

when you tap a new scope button the selectedScopeButtonIndex fires:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption;

you could capture the title fire off your search here using:

[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]

Won't work on the initial scope index, but you could just fire off your search initially based on the last used selectedScopeButtonIndex

like image 103
Nik Burns Avatar answered Oct 01 '22 01:10

Nik Burns


I was after the same thing and just found something in the Apple developer forums: The UISearchDisplayController is implemented in a way that the results table won't be shown until some text is entered. There's also a bug report about this: ID# 8839635.

I worked around it by putting a segmented control underneath the search bar, imitating the scope bar.

like image 29
Sebastian Avatar answered Oct 01 '22 00:10

Sebastian