2015-04-17 91 views
0

我有兩個文本框;點擊一個我打開pickerView,然後點擊下一個文本框我想從視圖中刪除上面打開的選擇器並打開鍵盤,但在textFieldShouldBeginEditing中使用[textfield becomeFirst Responder] textfield委託方法我得到EXC_BAD_ACCESS代碼崩潰。textfield becomeFirstResponder給出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; 
} 

回答

3

調用在textFieldShouldBeginEditing:[codeTextField becomeFirstResponder];將調用再次textFieldShouldBeginEditing:,這可能會導致錯誤。你不應該打電話[codeTextField becomeFirstResponder];,因爲它已經成爲第一響應者。

+0

是的在這種情況下textFieldShouldBeginEditing被迭代調用。我在textfieldShouldReturn中實現了我,它工作了! –