NSNotification postNotificationName in AppDelegate but NSNotificationCenter in ViewController?

Posted by James Testa on Stack Overflow See other posts from Stack Overflow or by James Testa
Published on 2011-01-02T05:16:39Z Indexed on 2011/01/02 7:53 UTC
Read the original article Hit count: 267

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?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa