User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

ios-labs-s14:intermediate-notif [2014/02/23 22:38] (current)
mbarboi created
Line 1: Line 1:
 +A method for sending app-wide messages to **anything** registered to hear them.
 +Any object can **register** for a notification by calling an Notification method for a given key. Any other object can post a notification,​ immediately alerting the first object of a given event. ​
 +Very useful for calling to objects that are unrelated to the sender, such as controllers in separate tabs of a TabBarController. Simultaneously extremely dangerous, since it creates code that is difficult to trace and catch errors from. To be used as a last resort for communicating information. ​
 +Registering for a notification:​
 +  [[NSNotificationCenter defaultCenter] addObserver:​self
 +        selector:​@selector(receiveTestNotification:​) ​
 +        name:​@"​TestNotification"​
 +        object:​nil];​
 +  -observer: the object to be notified
 +  -selector: the method to be called when the notification comes in
 +  -name: the key the notification is registered under; notifications with different keys will not be received
 +  -object: some object passed with the notification
 +Posting a notification
 +  [[NSNotificationCenter defaultCenter] ​
 +        postNotificationName:​@"​TestNotification" ​
 +        object:​self];​
ios-labs-s14/intermediate-notif.txt ยท Last modified: 2014/02/23 22:38 by mbarboi