我有两个字段,fldPassword和fldUsername。使用此代码(并加载了视图中的自委托),我希望返回键在两个文本字段中都消失。但是,它仅在第一时间执行。我究竟做错了什么?

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (fldPassword == self->fldPassword) {
        [fldPassword resignFirstResponder];
    } else if (fldUsername == self->fldUsername) {
        [self->fldUsername becomeFirstResponder];
    }

    return YES;
}

最佳答案

您只解雇了第一个,请尝试以下操作:

    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
        if (fldPassword == self->fldPassword) {
            [fldPassword resignFirstResponder];
        }
        if (fldUsername == self->fldUsername) {
            [self->fldUsername resignFirstResponder];
        }

        return YES;
    }

10-06 13:32
查看更多