NSNotification center and multiple objects
NSNotification center and multiple objects
- Subject: NSNotification center and multiple objects
- From: email@hidden
- Date: Wed, 31 Jan 2007 14:55:11 -0500
I seem to be having some trouble getting my head around something:
I have an NSObject class "PriorityManager" that posts a notification
to the defaultCenter in one of its methods, like this:
[[NSNotificationCenter defaultCenter] postNotificationName:
@"PriorityChanged" object: self];
In my controller class, I create and init a few of these
PriorityManager objects and put them into a NSMutableDictionary. Also
when doing so, I register the Controller as an observer:
/* Start enumerating through an array and set up the managers for each
index */
NSEnumerator *enu = [myDictionary objectEnumerator];
NSMutableDictionary * myObject ;
while (myObject = [enu nextObject]) {
PriorityManager *manager = [[PriorityManager alloc]
initWithIndex:[myObject valueForKey:@"index"];
[priorityManagers setObject:manager forKey:[myObject
valueForKey:@"name"]]; // obviously priorityManagers is also a
NSMutableDictionary
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(priorityDidChange)
name:@"PriorityChanged"
object:manager];
}
- (void)priorityDidChange {
NSLog(@"Controller recieved message that priority changed.");
}
I omitted out a few other things to simplify this a bit, but this is
pretty much the gist of it. The rest of my app code has work fine, but
I recently needed to do something in my controller based on a change
in the manager objects. So I thought this approach would work. If I
register the Manager class as an observer to its self the same way,
it works. But the notifications are just not getting to the
controller. Any idea where I am approaching this wrong?
Thanks,
Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden