UIKeyboardWillShowNotification not working with iOS> 6.1

Init section:

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

Some methods:

 - (void) keyboardWillShow:(NSNotification*) aNotification { // TO DO } 

Dealloc Section:

 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 

So, the WillShow keyboard does not get called after presenting the view in iOS 6.1 ... In iOS 6.0, this code works fine.

+4
source share
1 answer

In which init section are observers added? For example, if your view controller is from a storyboard, then it should be in - (id)initWithCoder:(NSCoder *)decoder .

My recommendation, however, is to set the watchers in viewWillAppear and remove them in viewWillDisappear . Thus, the setting and stall are β€œbalanced” and only active when the contents of the view controller are visible.

+2
source

Source: https://habr.com/ru/post/1482211/


All Articles