On any "view" to have to update, on the init method or on the awakeFromNib
method you add this line of code to register to a given notification. You
choose the name of the notification e.g. UnderlyingDataHasChanged, and the
method that has to be called, e.g. RefreshMe:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(RefreshMe:) name:@"UnderlyingDataHasChanged" object:nil];
Then you define the RefreshMe: method, on the view subclass, as your wish
- (void)RefreshMe:(id)notification
{
// you get the object newData, if any, this way
// id newData = [notification object];
[self setNeedsDisplay:YES]; // or whatever you need
}
So, now, when you get new data and you want to refresh all the views who
registered to the UnderlyingDataHasChanged notification, you just call
id newData = [something that sent you the new data];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"UnderlyingDataHasChanged" object:newData];
Last, in the dealloc method of "any" view who registered to the
UnderlyingDataHasChanged notification, you "must" unregister this way
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:@"UnderlyingDataHasChanged" object:nil];
[super dealloc];
}
Regards
--Leonardo
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]