I am using a UISearchBar to match text input against entries in a database and display the matched results to the user in a UITableView, as they type.
All is well, however, I cannot find a way to alter the return key type of the search bar’s keyboard. By default it replaces the standard return key with a Search button. Because I am doing a live search as the user types, I do not need this button and having it there and inactive has raised some usability issues.
Attempted solutions
-
I can set a keyboard with the
setKeyboard:UIKeyboardTypemethod, however this doesn’t seem to override the default setting of replacing the return key (on the standard keyboard) with a Search key and it does not allow access to change this return key. -
I have thought about using a
UITextField, giving me access to thereturnKeyTypeproperty through theUITextInputTraitsprotocol. My problem with this however is that I am implementing theUISearchBarDelegatemethodsearchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText, which I would lose with theUITextField.
Is there a way that I can keep the functionality of the search bar’s delegate methods, whilst having legitimate access to the keyboard’s return key?
In fact, almost the exact screen I am implementing is found in Apple’s Clock application
Screenshot:

So any help on a clean solution would be much appreciated. Note the return key on the bottom right instead of the default Search button’.
Try this:
for(UIView *subView in searchBar.subviews) { if([subView conformsToProtocol:@protocol(UITextInputTraits)]) { [(UITextField *)subView setKeyboardAppearance: UIKeyboardAppearanceAlert]; } }If you want to dismiss the return key (i.e., make it do nothing), set the “returnKeyType” property on the UITextField subview to “UIReturnKeyDone” along with “keyboardAppearence”.