views:

58

answers:

3

Hi,

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

+1  A: 

Type * and use that as a placeholder in your program for "" (nothing).

Jordan
A: 

Searching for "" is like searching for nil / NULL: the query will return all entries that are empty or null.

The * is a wildcard character used in most searching markups, and it'll return all matches.

Sean
Just to clarify further, `""` is **not** nil / NULL, but it's considered the *null string* (empty string).
Sean
+1  A: 

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;
Daniel Dickison
I like this answer too, but I don't think it's intuitive from a user experience point of view.
Jordan