UINavigationController should delegate -disablesAutomaticKeyboardDismissal to its top view controller

Originator:ben.kennedy
Number:rdar://16680390 Date Originated:21-Apr-2014 03:54 PM
Status:Open Resolved:
Product:iOS Product Version:iOS 7.1 (11D167) and probably earlier.
Classification:Enhancement Reproducible:Always
 
Summary:
For reasons not explained in the documentation, UIViewController presents an irrationally inconsistent behaviour of refusing keyboard dismissal when presented modally as UIModalPresentationFormSheet. In order to achieve standard behaviour, the view controller must override -disablesAutomaticKeyboardDismissal to return YES. Unfortunately, everything falls apart when the view controller in question exists within a UINavigationController stack that is presented modally UIModalPresentationFormSheet (because the latter returns NO per its superclass implementation), despite the wishes of the salient view controller. To mitigate this, a view controller presented modally within a navigation stack is forced to first subclass UINavigationController—a poor workaround.

To address this, two options are obvious:

1. UINavigationController could pass through -disablesAutomaticKeyboardDismissal to its topViewController, thus allowing the latter UIViewController to make its own decision about keyboard handling.

2. The obscure UIModalPresentationFormSheet behaviour could be abandoned entirely.


Example workaround in the mean time:

@interface KeyboardDismissibleNavigationController : UINavigationController
@end

@implementation KeyboardDismissibleNavigationController

- (BOOL)disablesAutomaticKeyboardDismissal
{
    return NO;
}

@end

…

UIViewController *vc = [MyUIViewController alloc] init]; // …
UINavigationController *nav = [[KeyboardDismissibleNavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:nil];

Steps to Reproduce:


Expected Results:


Actual Results:


Version:
iOS 7.1 (11D167) and probably earlier.


Notes:


Configuration:


Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!