UIKeyboardDidShowNotification called in two ViewControllers
I have one view controller (UICollectionView) that contains textfields. In
this controller I listen for UIKeyboardDidShowNotification:s. Like this:
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification
object:nil];
}
And in viewWillAppear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self registerForKeyboardNotifications];
[...]
In another view controller I have a UITextView. This controller also
listens for UIKeyboardDidShowNotification. Before I push this second view
controller I remove the first view controller as an observer:
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
But when the keyboard appears in VC2, then the keyboardDidShow actions
also gets called in VC1, causing unwanted animations. Is it possible to
avoid this behaviour somehow?
Update The strange thing is that the notification actions in VC1 gets
called when I tap the back button in VC2.
No comments:
Post a Comment