我有两个文本域;点击一个我打开pickerView
然后点按下一个文本字段我想从视图中删除上面打开的选择器并打开键盘,但在[textfield becomeFirst Responder]
textfield委托方法中使用textFieldShouldBeginEditing
我得到EXC_BAD_ACCESS代码崩溃。
代码是这样的:
- (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;
}
答案 0 :(得分:3)
在[codeTextField becomeFirstResponder];
中调用textFieldShouldBeginEditing:
会再次调用be textFieldShouldBeginEditing:
,这可能会导致错误。您不应该致电[codeTextField becomeFirstResponder];
,因为它已经成为第一个响应者。