• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNotification center and multiple objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNotification center and multiple objects


  • Subject: Re: NSNotification center and multiple objects
  • From: Mike Abdullah <email@hidden>
  • Date: Wed, 31 Jan 2007 20:02:26 +0000

To me it looks like the objects you are registering as an observer of are actually different to the objects that eventually send the notification. Try doing:

[[NSNotificationCenter defaultCenter] addObserver:self
	selector:@selector(priorityDidChange)
	name:@"PriorityChanged"
	object: nil];

See if you receive the notifications then.

Mike.

On 31 Jan 2007, at 19:55, email@hidden wrote:

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:
40mikeabdullah.net


This email sent to email@hidden

_______________________________________________

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


References: 
 >NSNotification center and multiple objects (From: email@hidden)

  • Prev by Date: Best way to determine if a path is a directory?
  • Next by Date: Re: NSNotification center and multiple objects
  • Previous by thread: NSNotification center and multiple objects
  • Next by thread: Re: NSNotification center and multiple objects
  • Index(es):
    • Date
    • Thread