Keyboard hide when switching views
I have 2 views: a login page and a register page. If a keyboard is shown when the user navigates to the other view, I want the program to dismiss the keyboard on its own. But upon navigating back to the login page from the register page, the keyboard shows automatically. Another thing is that when I switch from register page with keyboard shown back to the login page, it kills off the login keyboard instead of register keyboard.
Here's my code.
-(void) viewWillDisappear:(BOOL)animated {
[currentTextField resignFirstResponder开发者_如何学运维];
}
-(IBAction) registerButton:(id) sender
{
Registers *registerview = [[Registers alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:registerview animated:NO];
}
-(IBAction)back:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
// Console log when I navigates with keyboardshown on login view to register view.
-28 11:27:45.518 LoginPage[457:207] Login view appear // loaded the app
2011-05-28 11:28:00.131 LoginPage[457:207] Login Keyboard appear // tap on TextField
2011-05-28 11:28:02.435 LoginPage[457:207] Login Keyboard disappear // Navigate to register view started
2011-05-28 11:28:02.440 LoginPage[457:207] Register view appeared
2011-05-28 11:28:02.443 LoginPage[457:207] Login view disappear
2011-05-28 11:28:07.370 LoginPage[457:207] Login view appear // Navigate back started
2011-05-28 11:28:07.372 LoginPage[457:207] Register view disappeared
2011-05-28 11:28:07.788 LoginPage[457:207] Login Keyboard appear
精彩评论