Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4.3 add action for keyboard return key [closed]

How to make the return key on the keyboard to perform an action of (IBAction).

like image 460
shakyeb Avatar asked Feb 20 '23 11:02

shakyeb


2 Answers

well it's simple just add :

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self yourButtonName:nil];
}
like image 101
user1540999 Avatar answered Feb 22 '23 01:02

user1540999


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;
}
like image 35
John Smith Avatar answered Feb 22 '23 00:02

John Smith