NSNotification not being sent when postNotificationName: called

Affian picture Affian · Jan 21, 2010 · Viewed 26.2k times · Source

I'm trying to get one instance of using NSNotificationCenter with addObserver and postNotificationName but I can't work out why it won't work.

I have 2 lines to code to add the observer and send the message in 2 different classes

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

and

[[NSNotificationCenter defaultCenter]postNotificationName:@"Event" object:self];

If I set the name to nil it works fine becuase it's just a broadcast, when i try and define a notification name the messages never get through.

Answer

James picture James · Jan 22, 2010

All my code makes use of NSNotifications like so:

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

[[NSNotificationCenter defaultCenter] postNotificationName:@"ScanCompleted" object:nil];

The first one is registering the notification and the second posting of the notification.