2

I have a search bar in my SearchViewController, and currently, when they type into it, there's no Go button, it shows only return. I want a Go button to show in the keyboard, and I want it to be connected to the - (IBAction)nextButton:(id)sender that I have connected to the existing next UIButton under the search bar.

How do I go about enabling this and connecting it in this way? To clarify, the search bar and next button were created in storyboard, not programmatically.

Ghobs
  • 839
  • 2
  • 14
  • 32
  • 1
    Found the answer here: http://stackoverflow.com/questions/13065868/action-of-the-go-button-of-the-ios-keyboard – Ghobs Oct 10 '14 at 18:34

1 Answers1

3
 [textField setReturnKeyType:UIReturnKeyGo];

or

- (void)setReturnKey {
 //use condition here(not empty field)

self.searchField.returnKeyType = UIReturnKeyGo;
}

the other thing as Ghobs said you can find here...

 - (BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];//Dismiss the keyboard.
//Add action you want to call here.
return YES;
 }

source for above code:Action of the "Go" button of the ios keyboard

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType

Community
  • 1
  • 1
Avis
  • 505
  • 4
  • 14