Here is what you do:
From the class sending the message, send a notification, for example:
[[NSNotificationCenter defaultCenter] postNotificationName: @"YOUR_NOTIFICATION_NAME" object: anyobjectyouwanttosendalong(can be nil)];
In view controllers in which you want to be notified of a notification when sending:
In viewDidLoad, do:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(METHOD_YOU_WANT_TO_INVOKE_ON_NOTIFICATION_RECEIVED) name:@"YOUR_NOTIFICATION_NAME" object:sameasbefore/nil];
Attention! Do not forget about it in your view of DidUnload ():
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"YOUR_NOTIFICATION_NAME" object:sameasbefore/nil];
Iβm not very sure about the object associated with notifications, but you can see what is here
NOTE. When only one object notifies another, you are better off using protocols :) But in this case, since there are several view controllers, use notifications
Sid Apr 25 '11 at 23:40 2011-04-25 23:40
source share