Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3661096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:16:11+00:00 2026-05-19T01:16:11+00:00

I can’t get the selector method, receiveChatText, in the NSNotificationCenter to execute and I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:16:11+00:00Added an answer on May 19, 2026 at 1:16 am

    I can’t get the selector method, receiveChatText, …

    First, it’s receiveChatText:, with the colon. This is important in Objective-C —receiveChatText: and receiveChatText do not refer to the same method.

    Second, “selector” does not mean what you think it means. A selector is the name of a method. You pass in the selector for the message you want the notification center to send to the observer. That is, you are telling the notification center “when this notification arrives, send a receiveChatText: message to me [the view controller]”.

    … in the NSNotificationCenter …

    The notification center doesn’t have a receiveChatText: method. Your observer (self) does, which is why that’s what you want the notification center to send the message to.

    … to execute and I am wondering if the problem is because the NSNotification postNotificationName is in AppDelegate.m …

    No such thing is in AppDelegate.m.

    The app delegate posts a notification.

    … but NSNotificationCenter is in ViewController.m?

    No such thing is in ViewController.m.

    The view controller observes for a notification.

    As long as the view controller adds itself as an observer before the app delegate posts the notification, this will work. If it doesn’t work, either one or both steps did not happen or they happened in the wrong order.

    I.E. can the postNotificationName know that the NSNotificationCenter is in another viewController file or is that something I need to tell it?

    The notification center isn’t in either file. [NSNotificationCenter defaultCenter] is a singleton object, shared throughout your entire application amongst any objects that want to use it. That’s how you’re able to use it to have the app delegate communicate to the view controller and any other objects that are observing for the notification.

    You are sending the default notification center a postNotificationName:object:userInfo: message. This is the same default notification center that you should have previously sent an addObserver:selector:name:object: message. As long as you start observing first, then send the notification to the same notification center, the notification center will be able to dispatch the notification to the observer(s) you added.

    Any ideas what could stop receiveChatText

    receiveChatText:

    from being executed when didReceiveMessage is called?

    1. didReceiveMessage did not post a notification. Assuming the code you showed in your question is accurate, this is not the case.
    2. The view controller is not observing for the notification. Since it starts observing on creation, perhaps it hasn’t been created yet. Or, it may be because you’ve overridden init rather than NS/UIViewController’s initWithNibName:bundle:. Be aware of what different classes’ designated initializers are; the documentation will usually say.
    3. The view controller is not observing for the notification yet: You posted the notification before the view controller started observing for it (i.e., before you created the view controller).

    You might also want to pass the chat text as the object of the notification, or in its userInfo, rather than forcing all observers of the notification to retrieve it from an unspecified source.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I get a 'when to use' for these and others? <% %> <%#
Can i get the source code for a WAMP stack installer somewhere? Any help
I need to solve the following question which i can't get to work by
Can anybody please tell me how to get ReSharper to replace multiple instances (instead
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can a LINQ enabled app run on a machine that only has the .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.