UIKeyboard下一个按钮不会转到下一个UITextField

时间:2013-02-19 07:52:39

标签: ios uikeyboard resignfirstresponder becomefirstresponder

我一直试图弄清楚如何让UIKeyboard上的下一个按钮加载下一个UITextField。我有两个单元格,名称和电子邮件我想使用下一步按钮从名称转到电子邮件。

到目前为止我已添加

//.h
 <UITextFieldDelegate>

然后我这样做是为了尝试将用户从Name传递给电子邮件

//.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;
}

它输入第一个if语句,然后使用resignFirstResponder从屏幕上移除键盘,但是它不会使用becomeFirstResponder加载新键盘..任何帮助解决这个问题都会非常适用。

1 个答案:

答案 0 :(得分:11)

这将从一个文本字段转到下一个textField ...

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

    else{
        [textField resignFirstResponder];
    }
    return YES;
}