Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIKeyboardWillShowNotification

I have an observer for UIKeyboardWillShowNotification and UIKeyboardWillHideNotification.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

It all works, except it works when the viewController is not currently visible.

I've tried comparing to self.navigationcontroller.topViewController but this doesn't work when I have a modal view presented as the topViewController is the one underneath the modal view controller.

like image 278
Fogmeister Avatar asked Jun 06 '13 15:06

Fogmeister


1 Answers

If you're using UIViewController you could register your instance for Keyboard Notifications when the view becomes visible inside viewWillAppear: and then de-register when the view gets hidden inside viewWillDisappear: This way you won't receive notifications when the view is not visible.

Hope this helps!

like image 98
LuisCien Avatar answered Sep 22 '22 01:09

LuisCien