Ghobs
Ghobs

Reputation: 859

How to associate iOS keyboard "go" button with UIButton?

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.

Upvotes: 2

Views: 1099

Answers (1)

Avis
Avis

Reputation: 505

 [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

Upvotes: 3

Related Questions