This is not too much as a warning to warn others for some time.
In the OS 3 / iPhone OS 3, the NSNetification Center (which is also believed to be Mac OS X and iOS 4) has the following behaviors:
If you want to have accurate specific information for yourself If you register multiple times, NSNotificationCenter
recognize this extremism and in turn will stop many notifications for you, such as you register for an overview Have done
This is almost never a behavior that you want to see and is almost always casual
Example:
I want my view controller to be a single network Receive information from the object, when new data will arrive:
- (zero) viewDidoadload [[Super Viewedload]; [[NSNotificationCenter defaultCenter] addObserver: auto selector: @selector (newDataArrived :) name: NewDataArrivedNotification object: [NetworkListener Shared NetworkListener]]; }
But before I already do the same thing in viewWillAppear
:
- (zero) view viewAppear { [Super viewWillAppear]; [[NSNotificationCenter defaultCenter] addObserver: auto selector: @selector (newDataArrived :) name: NewDataArrivedNotification object: [NetworkListener Shared NetworkListener]]; }
Note that this is the OK that solves the same information, the same observer, sender and notification name.
In this case, if I do not remove one of those addobars calls, I will get duplicate notifications for my view controller.
In a multi-threaded environment, it is a world of sadness.
If you have specific precise notifications To register yourself several times, NSNotificationCenter will recognize no redundancy and instead you will be turned off as many notifications as you have registered for an overview.
This is almost never a behavior that you want to see and is almost always casual. Example:
I want my view controller to get information from a Newton Network object when new data comes:
- (Zero) viewDidoadload [[Super Viewedload]; [[NSNotificationCenter defaultCenter] addObserver: auto selector: @selector (newDataArrived :) name: NewDataArrivedNotification object: [NetworkListener Shared NetworkListener]]; }
But before I already do the same thing in viewWillAppear
:
- (zero) view viewAppear { [Super viewWillAppear]; [[NSNotificationCenter defaultCenter] addObserver: auto selector: @selector (newDataArrived :) name: NewDataArrivedNotification object: [NetworkListener Shared NetworkListener]]; }
Note that this is the OK that solves the same information, the same observer, sender and notification name.
In this case, if I do not remove one of those addobars calls, I will get duplicate notifications for my view controller.
In a multi-threaded environment, it is a world of sadness. Believe me.
Just by keeping it out there are other people in the case who run something like this.
Comments
Post a Comment