简体   繁体   English

文本字段成为FirstResponder给出EXC_BAD_ACCESS代码

[英]textfield becomeFirstResponder gives EXC_BAD_ACCESS code

I have two textfields; 我有两个文本字段; on tap of one I open a pickerView and on tap of next textfield I want to remove above opened picker from view and open keyboard but using [textfield becomeFirst Responder] in textFieldShouldBeginEditing textfield delegate method I get EXC_BAD_ACCESS code crash. 单击一个我打开pickerView ,然后单击下一个文本字段,我想从视图中删除上面打开的选择器,然后打开键盘,但是在textFieldShouldBeginEditing文本字段委托方法中使用[textfield becomeFirst Responder] ,我得到EXC_BAD_ACCESS代码崩溃。

The code is as such: 代码是这样的:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField == earningCodeTextField) {
    [self dismissKeyboard];
    [self showPickerView];
    return NO;
}
else if (textField == codeTextField) {
    [self hidePickerView];
    [codeTextField becomeFirstResponder];
    return YES;
}
return YES;
}

Calling [codeTextField becomeFirstResponder]; 调用[codeTextField becomeFirstResponder]; in the textFieldShouldBeginEditing: will call the be textFieldShouldBeginEditing: again and this might cause the error. textFieldShouldBeginEditing:中将再次调用be textFieldShouldBeginEditing: ,这可能会导致错误。 You should not call [codeTextField becomeFirstResponder]; 您不应该调用[codeTextField becomeFirstResponder]; because it is already becoming the first responder. 因为它已经成为第一响应者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM