Getting past UINavigationController keyboard dismiss bug/feature
When programming on iOS, if you make a view that segues to a modal Form Sheet view through a UINavigationController, a weird issue happens where the keyboard won't go away when TextBoxes resignFirstResponder status. (e.g., [myTextField resignFirstResponder])
Apple considers this a feature that prevents too many animations of the keyboard coming into and out of the screen. Of course, this does not help when the 'feature' is undesirable.
The way this is addressed is that the navigation controller requires the method "disablesAutomaticKeyboardDismissal" to always return NO. Making that method is easy:
-(BOOL)disablesAutomaticKeyboardDismissal;
-(BOOL)disablesAutomaticKeyboardDismissal {
The difficult part is that this needs to be put in the UINavigationViewController. If you aren't using a custom ViewController for it already, this could be tricky.
The best ways is to use a feature called categories.
1) open the NEW FILE dialog
2) go to iOs > Cocoa Touch > Objective-C category
3) give it a name (e.g., 'KeyboardDismiss') and change Category on to 'UINavigationController'.
4) Put the method into the new file. The files should look as follows
//Â UINavigationController+KeyboardDismiss.h
//Â Created by APS on 11/23/13.
//Â Copyright (c) 2013 Alex Z. All rights reserved.
@interface UINavigationController (KeyboardDismiss)
-(BOOL)disablesAutomaticKeyboardDismissal;
//Â UINavigationController+KeyboardDismiss.m
//Â Created by APS on 11/23/13.
//Â Copyright (c) 2013 Alex Z. All rights reserved.
#import "UINavigationController+KeyboardDismiss.h"
@implementation UINavigationController (KeyboardDismiss)
-(BOOL)disablesAutomaticKeyboardDismissal {
5) It seems like this does not need to be linked in the storyboard but if issues arise, try to link it up by selecting the Navigation view controller in the storyboard, go into the identity inspector and enter the class name of the new class you made in the Custom Class field.