9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UINavigationController resignFirstResponderでキーボードが閉じない場合の対処法

Posted at

UINavigationControllerをUIModalPresentationFormSheetで表示している時にポップ時やresignFirstResponderを明示的に呼んでもキーボードが閉じない場合の対処法です。
バグではなく仕様のようです。

対処法

UINavigationControllerで

- (BOOL)disablesAutomaticKeyboardDismissal

をオーバーライドしNOを返せばポップ時やresignFirstResponderでキーボードを閉じることができます。

UIViewControlelrで宣言されているので(カテゴリで宣言されていないので)UINavigationControllerのカテゴリでオーバーライドしても問題はないです。
個別で対応が必要な場合はサブクラスで対応すればよいかと思います。

UINavigationController+KeyboardDismiss
@implementation UINavigationController(KeyboardDismiss)

- (BOOL)disablesAutomaticKeyboardDismissal
{
    return NO;
}

@end

参考

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?