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

  • SEARCH
  • Home
  • 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 8881805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:25:14+00:00 2026-06-14T20:25:14+00:00

I have have been trying to get NSNotification to work. For a test, I

  • 0

I have have been trying to get NSNotification to work. For a test, I wanted a button that loads a new viewController using storyBoards. When you click the button it should trigger a notification for the appObserver to pick up in the second ViewController (I’ve named Page2). In Page2 the the NSNotificationCenter should launch a method (myMethod:) and print out a simple NSLog.
Unfortunately, it doesn’t work as myMethod does not get called. what am I doing wrong ???

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (IBAction)goToPage2Button:(id)sender {

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

}

#import "Page2.h"

@interface Page2 ()

@end


@implementation Page2

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
       [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(myMethod:) name:@"test" object:nil];


    }
    return self;
}

-(void)myMethod:(NSNotification *)notification{


    if ([[notification name] isEqualToString:@"test"])
        NSLog (@"Successfully received the test notification!");


}
  • 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-06-14T20:25:15+00:00Added an answer on June 14, 2026 at 8:25 pm

    I think this could be because your page2 view controller does not exist when the notification is fired.

    The second view controller registers for observation when it wakes from it’s nib, but if it hasn’t been created, then it hasn’t registered for the notification that your first view controller is sending.

    What you should be doing is using segues to load view controllers based on actions.

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

Sidebar

Related Questions

I have been trying to get a handle on using MVC 4.0 with EF
I have been trying to get Twitter Bootstrap btn-group with dropdown to work for
I have been trying to get a custom Value from the Custom Field that
I have been trying to get nServiceBus to work with Ninject 2.0 as the
I have been trying to get LastBootUpTime using Win32_OperatingSystem class (WMI). HRESULT hr =
Have been trying to get a fresh, just created rails application to work on
I have been trying to get the PCP LibJingle example to work for several
We have been trying to get the Editor-Template to work with a dynamic property
I have been trying to get this to work. Basically I have a search
I have been trying to get this to work for most of the day

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.