NSNotification postNotificationName in AppDelegate but NSNotificationCenter in ViewController?
- by James Testa
I can't get the selector method, receiveChatText, in the NSNotificationCenter to execute and I am wondering if the problem is because the NSNotification postNotificationName is in AppDelegate.m but NSNotificationCenter is in ViewController.m? I.E. can the postNotificationName know that the NSNotificationCenter is in another viewController file or is that something I need to tell it?
In a viewController.m I have
-(id)init
{
self = [super init];
if(self){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveChatText:)
name:ChatMessageReceived
object:nil];
return self;
}
- (void)receiveChatText:(NSNotification *)note {
NSLog(@"received chat text");
}
and in the top level AppDelegate.m file I have the following:
-(void) didReceiveMessage {
[[NSNotificationCenter defaultCenter] postNotificationName:ChatMessageReceived
object:nil
userInfo:nil];
}
Any ideas what could stop receiveChatText from being executed when didReceiveMessage is called?