UITextField
개체가 여러 개인보기에서 작업하고 있습니다. 내보기 컨트롤러는 UITextFieldDelegate
의 역할을하며 표시되는 레코드를 저장하고 유효성을 검사하기 위해 (BOOL)textFieldShouldEndEditing:(UITextField *)textField
메서드를 구현했습니다.textFieldShouldEndEditing 여러 번 호출 됨
항목을 편집 한 후 "완료"버튼을 클릭하고 저장/유효성 검사에 실패하면 UIAlertView
이 표시되고 유효성 검사에 실패한 UITextField
에 계속 보관됩니다.
내 문제는 이것이다 - 사용자가 UITextField
의 또 다른에/검증 저장 실패합니다 UITextField
에서 클릭 할 때, 다음 (BOOL)textFieldShouldEndEditing:(UITextField *)textField
방법은 여러 번 호출을하고 UIAlertView
여러 번 나타납니다.
사용자가 키보드에서 "완료"를 클릭하면 사용자가 UITextField
을 클릭 할 때 여러 번 호출되면 (BOOL)textFieldShouldEndEditing:(UITextField *)textField
이 한 번 호출되는 이유는 무엇입니까? 나는 당신의 문제가 된 TextField 방법은 당신이 TextField를 편집 할 때 전화를 직접 서로에 탭 순서에서 오는 생각
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@"textFieldShouldEndEditing called by textField with text=%@", textField.text);
currentItem.nameOrNumber = nameOrNumber.text;
// Try to save the managed object.
NSError *error = nil;
if (![[currentItem managedObjectContext] save:&error]) {
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Uh Oh!",@"")
message:[error localizedDescription]
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK",@"")
otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
shouldEnd = NO;
}
return shouldEnd;
}