iPad keyboard will not dismiss if modal view controller presentation style is UIModalPresentationFor

在ipad上present 一个 navigation controller 时,present后弹出的keyboard,不能够 dismiss 掉。即使 textfield resignFirstResponder,keyboard也不会消失。

Problem:

在iPad keyboard上发现一个问题,当viewController在navigation controller下以模态视图弹出,并且navigationController.modalPresentationStyle = UIModalPresentationFormSheet时,点击done按钮,软键盘不撤销,即使 textfield resignFirstResponder了。

Solution:

当模态视图在 UINavigationControlle下显示,我们需要设置 navigation controller的disablesAutomaticKeyboardDismissal属性,我们可以通过添加类别实现这个。

File: UINavigationController+KeyboardDismiss.h

#import

@interface UINavigationController (KeyboardDismiss)

- (BOOL)disablesAutomaticKeyboardDismissal;

@end

File: UINavigationController+KeyboardDismiss.m

#import "UINavigationController+KeyboardDismiss.h"

@implementation UINavigationController(KeyboardDismiss)

- (BOOL)disablesAutomaticKeyboardDismissal

{

return NO;

}

@end

在需要用到的ViewController文件中导入创建的类别即可。

iPad keyboard will not dismiss if modal view controller presentation style is UIModalPresentationFor

时间: 2024-08-06 11:58:33

iPad keyboard will not dismiss if modal view controller presentation style is UIModalPresentationFor的相关文章

iOS开发报错之attempt to dismiss modal view controller whose view does not currently appear

刚才遇到一个问题,现在在这就当纪录一下,大家有遇到的能快速找到原因,分享一下啊. 在APP中,需要用户登录后才能使用,所以我通过更改APP的[UIApplicationsharedApplication].keyWindow.rootViewController来控制界面的跳转. 在使用过程中出现如下问题: 1.登录成功后点击注销按钮,弹出注销提示框UIAlertView: 2.注销成功后重新登录: 3.再次点击注销不再弹出UIAlertView. 提示如下警告: 点击注销按钮执行更改rootv

Application tried to present a nil modal view controller on target “Current View Controller”解决方案

情景再现 1,自定义一个storyboard: 打开xcode,按下cmd+N,新建一个Storyboard--->next 将新建立的storyboard命名为:TestViewController--->create 在TestViewController.storyboard上加上一个label,其text为:Hello-ios 2,编写UIButton的UIControlEventTouchUpinside事件: - (IBAction)btnClick:(id)sender { //

iOS 跳转出现attempt to dismiss modal view controller whose view does not currently ……的解决方案

今天在设置修改密码成功进行跳转到登录页面重新登录的时候,我写的原代码是: [self dismissViewControllerAnimated:YES completion:nil]; [UIApplication sharedApplication].keyWindow.rootViewController = [[loginViewController alloc]init]; 于是出现了在本页面跳到登录页面,然后又切回到本页面的状况.如图: 首先是修改密码的页面: 点击确认以后,跳转到登

Chapter 17 Autorotation, Popover Controller, and Modal View Controllers

1.There are two distinct orientations in iOS: device orientation and interface orientation. The device orientation represents the physical orientation of the device, whether it is right-side up, upside down, rotated left, rotated right, on its face,

iOS Programming Autorotation, Popover Controllers, and Modal View Controllers

iOS Programming Autorotation, Popover Controllers, and Modal View Controllers? 自动旋转,Popover 控制器,Modal view controller? 1.? In this chapter, you are going to make four changes to Homepwner's behavior that will tailor the app's behavior to whatever dev

【IOS笔记】View Controller Basics

View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen space for displaying content and therefore must be creative in how they present information to the user. Apps that have lots of information to display

Model View Controller

On the iPhone or iPod touch, a modal view controller takes over the entire screen. This is the defaultbehavior and the only possibility on these devices. On the iPad, you have two additional options: aform sheet style and a page sheet style. You can

View Controller Relationships

Parent-child relationshipsParent-child relationships are formed when using view controller containers. Examples of viewcontroller containers are UINavigationController, UITabBarController, and UISplitViewController. You can identify a view controller

设置view controller到iPhone或者iPad模式

在写iOS程序时,view controller的显示大小以及控件大小的调节是在是一个费力的事,尤其是对于用mac本的童鞋,更难驾驭,这时我们可以根据需要设置专门针对iphone或者ipad的view controller的大小,可以修改设置项“Use Size Classes": 当选中时:view controller能同时适用iPhone和ipad的尺寸 未选中时:有提示框来指导是用iPhone的尺寸还是ipad得尺寸,运行时会根据选择的simulator变化