5

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.

HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
  • Sure that customerEmailTextField is not nil? – Alexander Feb 19 '13 at 07:57
  • I have to change the second part of the if statment.. but im not quite sure what you are refering too? – HurkNburkS Feb 19 '13 at 08:01
  • If customerEmailTextField is nil your code [customerEmailTextField becomeFirstResponder] wouldn't work obviously... – Alexander Feb 19 '13 at 08:02
  • 1
    I don't think you need to resignfirstresponder if your telling the next field to becomefirstresponder. Also, I think you should be returning NO. – Bushbert Feb 19 '13 at 08:04
  • I hope this isnt too much of a stupid question but how do I stop it from being nil?.. okay just read your suggestion.. I am going to try now. – HurkNburkS Feb 19 '13 at 08:06

1 Answers1

12

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;
}
Sudha Tiwari
  • 2,499
  • 26
  • 50