Keyboard not dismissing when UIAlertView with textfields is dismissed
I would make sure to show the alert late in the view life cycle of the view controller that's presenting it, eg
- (void)viewDidAppear {
    [super viewDidAppear];
    [self performSelector:@selector(showTheAlert) afterDelay:0.0];
}
- (void)showTheAlert {
    // alloc, init and show the alert here
}
And I'd use a delegate callback to give the textView first responder, eg
- (void)didPresentAlertView:(UIAlertView *)alertView {
    [theUsernameTextField becomeFirstResponder];
}
And I'd use the delegate for any dismissal to resign. There's no downside to resigning first responder on a text field that isn't the first responder, so just resign both.
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    [theUsernameTextField resignFirstResponder];
    [thePasswordTextField resignFirstResponder];
}
You can conform self as a delegate of your UIAlertView once you create one. After that in:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
method you can get reference to your text field and you can call resignFirstResponder on it.
实现下面的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
      UITextField *txtField = [alertView textFieldAtIndex:buttonIndex];
      [txtField resignFirstResponder];
}
                        链接地址: http://www.djcxy.com/p/44228.html
                        
                        
                    