Reputation: 5208
I am creating a notification on viewdidload UIKeyboardWillShowNotification and removing it on viewwilldisappear.
When the keyboard appear on screen and its notification is called once as expected, I locked the screen. The notification is called 4 times and creating undesired functionality.
Why the notification being called? how can i prevent from this scenario?
I am adding Observer for notification in viewdidload in this manner
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
EDIT: Same results if i send the app to background instead of lock screen.
Upvotes: 1
Views: 1088
Reputation: 2786
that same thing was happend with me
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
i was presenting a view controller on button click. every time i present Viewcontroller viewdidload get called it add the addObserver. so the method get called multiple time.
Upvotes: 2
Reputation: 5592
In your case Notification calls multiple times that shows the addObserver calls multiple time or you are not removing observer once its usage is done.
Simply follow this things :
viewwilldisappear
method. So try to debug & see if it gets called. If this method not getting called try to remove it in viewDidUnload
method.Note :
Hope it will help you.
Upvotes: 0