/ Published in: Objective C
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Mutliple observers can be notified of events. notification sent by a specific object... [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFooHappened:) name:MyFooNotification object:foo]; set object to nil to receive notifications of that name sent by ANY object. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFooHappened:) name:MyFooNotification object:nil]; Format for myFooHappened is.. // [note name] - name of notification [note object] - sender // [note userInfo] is an NSDictionary of key-value pairs filled by the sender. } Note: notifications are posted on the SAME THREAD as they were posted. MUST unregister from all notifications in your dealloc -(void) dealloc } Posting a notification.. Define a constant for the name of the notification.. in .h in .m -(void) postFoo { [[NSNotificationCenter defaultCenter] postNotificationName:MyFooNotification object:self userInfo:[NSDictionary ...]];