Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: UISearchBar how to search for "" String?

I want to be able to search for a String without any character in it. The problem is, that the default keyboard does not show up the search button, when there is nothing written in the UISearchBar.

Any idea?

Thanks, Markus

like image 203
Markus Avatar asked Oct 02 '10 18:10

Markus


1 Answers

Luckily, I just happened to be working on code that does exactly this. It's a bit of a hack, but you can find the UITextField that is embedded within the UISearchBar, then turn off enablesReturnKeyAutomatically:

UITextField *searchBarTextField = nil;
for (UIView *subview in searchBar.subviews)
{
    if ([subview isKindOfClass:[UITextField class]])
    {
        searchBarTextField = (UITextField *)subview;
        break;
    }
}
searchBarTextField.enablesReturnKeyAutomatically = NO;
like image 154
Daniel Dickison Avatar answered Sep 21 '22 07:09

Daniel Dickison