Why is my NSNotification its observer called multiple times?

后端 未结 5 2119
一个人的身影
一个人的身影 2020-12-15 04:48

Within an App I make use of several viewcontrollers. On one viewcontroller an observer is initialized as follows:

[[NSNotificationCenter defaultCenter] remov         


        
5条回答
  •  别那么骄傲
    2020-12-15 05:01

    it is quite possible you are subscribing to the notifications

    [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:self userInfo:userInfo];
    

    before self gets initialized. And trying to unsubscribe 'self' which isn't really subscribed to, and you will get all global myNotification notifications.

    If your view was hooked up in IB, use -awakeFromNib: as the starting point to register for notifications

提交回复
热议问题