切换到另一个视图时隐藏键盘

时间:2011-07-19 10:59:49

标签: ios view keyboard hide switch-statement

我有2个视图,登录和注册。

我做了[currentTextField resignFirstResponder];在我导航到另一个视图之前。

问题是,键盘仅在切换视图后才隐藏。因此,在另一个混乱的视图中触发了keyboardDidShow方法。

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?

我想知道为什么在我清楚地将视图置于其上方时切换视图后才进行resignFirstResponder。

-(IBAction) registerButton:(id) sender
{
[currentTextField resignFirstResponder];
Registers *registerview = [[Registers alloc] initWithNibName:nil bundle:nil];
[UIView beginAnimations:@"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];

}

1 个答案:

答案 0 :(得分:1)

你可以在进入第二个视图之前加一些延迟,这样键盘就会隐藏起来。尝试[self performSelector:withObject:afterDelay:0.35]; //在调用此resign当前文本字段之前,将选择器传递给@selector(displaySecondView)。