views:

36

answers:

2

Hi there, I'm looking for a way to enable the "Search"-Button on the Keyboard even tough the search bar's text field doesn't contain text at that very moment.

background is, that along with the term entered in the search bar's textfield i'll send other information to my backend. A Search for a null-term would then make sense (in my scope)..

is there any way to solve this problem?

thx in advance,

sam

A: 

It would be a better idea to just have a button or link for "Show All" or some similar thing.

js1568
A: 

You could try adding an invisible character to the beginning of the search text field when it becomes active. A Zero-width space might be just the thing.

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController*)controller
{
    NSLog(@"Starting search");  
    controller.searchBar.text = @"\u200B";
}

You might want to combine it with something like this to prevent a reload of the table data:

- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString
{
    return ![searchString isEqualToString:@"\u200B"];
}
bosmacs
i love those hacks! thanks a lot!
samsam