Hide keyboard when switching to another view
I have 2 views, login and register.
I did [currentTextField resignFirstResponder]; before I navigates to the other view.
The problem is, the keyboard is only hidden after it switched view. Which thus fired the keyboardDidShow method on the other view which messes stuff up.
2011-07-19 18:55:33.315 Prime Taxi Booking[601:207] Login view appear // lauched app
2011-07-19 18:55:34.952 Prime Taxi Booking[601:207] Login Keyboard appear // starts typing
2011-07-19 18:55:37.033 Prime Taxi Booking[601:207] Register view appeared // navigation
2011-07-19 18:55:37.036 Prime Taxi Booking[601:207] Login view disappear
2011-07-19 18:55:37.360 Prime Taxi Booking[601:207] Register Keyboard disappear // ?? how do I make this to disappear login keyboard instead?
I wonder why did it only resignFirstResponder after switching views when I clearly placed it above it.
-(IBAction) registerButton:(id) sender
{
[currentTextField resignFirstResponder];
Registers *registerview = [[Registers alloc] initWithNibName:nil bundle:nil];
[UIView b开发者_JS百科eginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:self.view.superview
cache:YES];
[UIView commitAnimations];
[self presentModalViewController:registerview animated:YES];
//[self.view addSubview:registerview.view];
}
you can put some delay before going to second view so that keyboard will hide. try [self performSelector: withObject: afterDelay:0.35];//Pass the selector like @selector(displaySecondView) before calling this resign current textfield.
精彩评论