如何使键盘上的回车键执行(IBAction)操作。
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[self yourButtonName:nil];
}
实现UITextFieldDelegate:
@interface yourClass : UIViewController<UITextFieldDelegate>
使用委托方法:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//do whatever you need here
//maybe you have several textFields, so first check which one was hit the return key:
if(textField == outlet_to_your_textField_1){
//do this
}
else if(textField == outlet_to_your_textField_2){
//do that
}
else if .... blablabla and so on
return YES;
}
这是我在 iPhone 键盘上按下 Return 键时如何处理的方法,软键盘会从文本视图返回。
这里有三种简单的处理键盘的方法:
希望这对你有所帮助。