Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIKeyboard next button not going to next UITextField

I have been trying to figure out how to get the next button on the UIKeyboard to load the next UITextField.. I have two cells, Name and Email I would like to go from Name to Email using the Next button.

so far I have added

//.h
 <UITextFieldDelegate>

then I am doing this to try and pass the user from Name to Email

//.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    customerNameTextField.delegate = self;
    customerEmailTextField.delegate = self;
//...

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (![customerNameTextField.text isEqualToString:@""]) {
        [customerNameTextField resignFirstResponder];
        [customerEmailTextField becomeFirstResponder];
    } else if (textField == customerEmailTextField) {
        // here you can define what happens
        // when user presses return on the email field
        // send request
    }
    return YES;
}

It enters the first if statment, then It removes the keyboard from the screen using resignFirstResponder but then it dose not load the new keyboard using becomeFirstResponder.. Any help fixing this would be greatly apprecaited.

like image 679
HurkNburkS Avatar asked Feb 19 '13 07:02

HurkNburkS


1 Answers

This will go from one textfield to next textField...

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == ist) {
        [second becomeFirstResponder];
    }
    else if (textField == second) {
        [third becomeFirstResponder];
    }

    else{
        [textField resignFirstResponder];
    }
    return YES;
}
like image 76
Sudha Tiwari Avatar answered Nov 07 '22 22:11

Sudha Tiwari