I looked at this site that I could not find a solution to the problem that I am currently facing. Hope someone can help.
I created UIAlertView to prompt the user to enter their name in the iPhone app.
UIAlertView *enterNameAlert = [[UIAlertView alloc] initWithTitle:@"Enter your name" message:@"\n\n\n" delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"OK", nil),nil]; UITextField *enterNameField = [[UITextField alloc] initWithFrame:CGRectMake(16, 83, 252, 25)]; enterNameField.keyboardAppearance = UIKeyboardAppearanceAlert; enterNameField.borderStyle = UITextBorderStyleRoundedRect; enterNameField.autocorrectionType = UITextAutocorrectionTypeNo; enterNameField.clearButtonMode = UITextFieldViewModeWhileEditing; enterNameField.returnKeyType = UIReturnKeyDone; enterNameField.delegate = self; [enterNameField becomeFirstResponder]; [enterNameAlert addSubview:enterNameField]; [enterNameAlert show]; [enterNameAlert release]; [enterNameField release];
I set this viewController to match UITextFieldDelegate in the header file and textFieldShouldReturn: to remove the keyboard when the user clicked Finish.
- (BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isFirstResponder]) { [textField resignFirstResponder]; NSLog(@"text field was first responder"); } else { [textField becomeFirstResponder]; [textField resignFirstResponder]; NSLog(@"text field was not first responder"); } NSLog(@"textfieldshouldreturn"); return YES; }
In the debugger, I confirm that this method is called successfully when I click the Finish button, with textField being the first responder at that time. However, the keyboard does not disappear, but the small clearButton leaves. It is clear that textField is no longer the first responder, because when I click the Finish button again, nothing is called. I just want to remove the keyboard using the "Finish" button. Can anyone suggest a solution? Thanks a million.
iphone uitextfield keyboard uialertview dismiss
Anthony
source share