Xcode 4.3 add action for keyboard return key
11,166
Solution 1
well it's simple just add :
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[self yourButtonName:nil];
}
Solution 2
Implement UITextFieldDelegate:
@interface yourClass : UIViewController<UITextFieldDelegate>
Use the delegate method:
- (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;
}
Related videos on Youtube
Author by
shakyeb
Updated on October 31, 2022Comments
-
shakyeb about 1 year
How to make the return key on the keyboard to perform an action of (IBAction).
-
Admin about 11 yearsBy reading UIControl's class reference.
-
-
shakyeb about 11 yearsi know, but i don't want to rewrite my code, what i want to do is just calling the IBAction, like i have a button and a textfield on a viewController then when the return key pressed it perform the action of the button
-
John Smith about 11 yearsBut how do you suppose to make it work without rewriting the code? Actually you have nothing to rewrite, just adding some lines... well maybe quite a bit, but it will take you little time. And I have no idea why do you ask this, and not intending to change parts of code.