2014-10-10 88 views
2

我在我的SearchViewController中有一個搜索欄,當前,當他們鍵入它時,沒有按鈕,它只顯示返回。我想要一個按鈕顯示在鍵盤上,我希望它連接到- (IBAction)nextButton:(id)sender,我已經連接到現有的UIButton在搜索欄下。如何將iOS鍵盤的「go」按鈕與UIButton相關聯?

我該如何去做到這一點,並以這種方式連接它?爲了澄清,搜索欄和下一個按鈕是在故事板中創建的,而不是以編程方式。

+1

找到該在這裏回答:http://stackoverflow.com/questions/13065868/action-of-the-but-button-of-the-ios-keyboard – Ghobs 2014-10-10 18:34:08

回答

3
[textField setReturnKeyType:UIReturnKeyGo]; 

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

self.searchField.returnKeyType = UIReturnKeyGo; 
} 

其他事情Ghobs說,你可以在這裏找到...上面的代碼

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

來源: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

相關問題