切换视图时键盘隐藏

时间:2011-05-28 03:15:42

标签: xcode view keyboard switch-statement hide

我有2个视图:登录页面和注册页面。如果在用户导航到另一个视图时显示键盘,我希望程序自己解除键盘。但是当从注册页面导航回登录页面时,键盘会自动显示。另一件事是,当我从显示键盘的注册页面切换回登录页面时,它会终止登录键盘而不是注册键盘。

这是我的代码。

   -(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

0 个答案:

没有答案