Dismissing the keyboard in detailViewController view


In Chapter 13 (and subsequent chapters), there seems to be a problem with dismissing the keyboard in the detailViewController view. I found a solution and thought I’d post it here in case other people are having the same problem (unless I missed something, perhaps this should be posted to the errata)

When adding a new item, detailViewController view will not dismiss its keyboard when clicking the view or pressing return. After some digging I found that when the view controller is set to UIModalPresentationFormSheet, it will not allow keyboard dismissal. You have to create a subclass of UINavigationController that overrides disablesAutomaticKeyboardDismissal.

See: developer.apple.com/library/ios/ … rence.html#//apple_ref/occ/instm/UIViewController/disablesAutomaticKeyboardDismissal

I just implemented one method in my new subclass:

  • (BOOL)disablesAutomaticKeyboardDismissal
    return NO;

and used the new class for “navController” in addNewItem:. This did the job.


I should specify that this problem occurs only on iPad.


I noticed the same issue. I’m pretty new at this, and I’m a little confused about your solution. Can you explain it a little more? Did you create a new Objective C class and then just implement that method in the .m file? Can you post the full code for your addNewItem method?

Also, did you run into the issue where the value field uses the standard keyboard instead of the decimal keyboard? I haven’t figured out how to fix that. On the iPhone it is still using the decimal keyboard.


Thanks @ksachd, you are a hero!

Here is a link to StackOverflow topic discussing the problem and solution, which is the same as @ksachd has stated.

@paolom, I think your guess is right that @ksachd created a new class derived from UINavigationController that just overrides that one method. I called mine “BNRNavigationController,” and invoked it in ItemViewController’s addNewItem method. (The only thing that changed was allocating and initializing an instance of BNRNavigationController rather than UINavigationController.)

Alternately, you can use a different modal presentation style. Our problem was first introduced in Chapter 13, section “Modal view controller styles”: we can use the UIModalPresentationFormSheet style, sure, but then we have this problem. Perhaps an Apple designer would tell us to use a different style. But I like it, so I’m going with subclassing.