How to HIDE the iPad keyboard from a MODAL view controller?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 21:15:58

Apparently, there is a new -[UIViewController disablesAutomaticKeyboardDismissal] method that you may override to solve this problem in iOS 4.3.

It was because I was using UIModalPresentationFormSheet. All of the other ones work as expected.... Wasted several hours on that.

This was a total pain to find. Seems like one of the poorer API designs in iOS. Much appreciation to @0xced and @manicaesar for the answers.

Here's my consolidated answer for future devs who are stuck beating their head against the wall.

If it's a single view controller, just override disablesAutomaticKeyboardDismissal and return NO.

If it's a navigation controller in a modal, create your own UINavigationController subclass like so:

In .h...


@interface MyNavigationController : UINavigationController

@end

In .m....

@implementation MyNavigationController


#pragma mark -
#pragma mark UIViewController
- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}

@end

In your code that shows a modal view controller.

UIViewController *someViewController = [[UIViewController alloc] init];

MyNavigationController *navController = [[MyNavigationController alloc] initWithRootViewController:someViewController];

navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];

I just confirmed the problem is indeed UIModalPresentationFormSheet and filed a bug report to apple rdar://8084017

azdev

I solved this by resizing a UIModalPresentationPageSheet. See my answer here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!