3

I have a regular text field on a view and I'd like to make use of the search button on the iPhones keyboard. For the life of me, I can't figure out how to do this. There doesn't seem to be any event exposed that I can wire up that specifically relates to the search button on the keyboard. I've googled around, but I also haven't found anything related to this subject.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
senfo
  • 28,488
  • 15
  • 76
  • 106
  • Are you asking how to display "Search" on the keyboard or how to make the Search button trigger an action? (or both) – kubi Apr 22 '10 at 13:28
  • I managed to find how display the search button, I just couldn't figure how to make it work. Thank you again for your response. That was exactly what I wasn't able to find. – senfo Apr 22 '10 at 13:50

1 Answers1

6

Make the keyboard display the blue "Search" button by setting the return key type.

myTextField.returnKeyType = UIReturnKeySearch;

Set the delegate of your text field to your controller and implement the 'textFieldShouldReturn:' method.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    /* Do some searching here */
    return YES;
}
kubi
  • 48,104
  • 19
  • 94
  • 118