NSNotificationCenter doesn't work in popup view(ios objC)

I'm working on a iPad project(xcode 7.21+iOS9) and NSNotificationCenter doesn't work.

When user open my app, the tab bar controller will appear.

- (void)viewWillAppear:(BOOL)animated {
    if (false == [[MyClass sharedData] getLoginStatus])
    {
        LoginViewController *loginViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"myCustomPopoverLoginVC"];
            loginViewController.modalPresentationStyle = UIModalPresentationFormSheet;
            [self presentViewController:loginViewController animated:YES completion:^{

        }];
...
    }
}

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLogin:) name:@"afterLogin" object:nil];
    [super viewDidLoad];
...
}

-(void)notificationLogin:(NSNotification *)notification{
    NSLog(@"OhOhOh");
}

In my loginView,

-(IBAction)login:(id)sender{
    ...
    [[NSNotificationCenter defaultCenter] postNotificationName:@"afterLogin" object:nil];
    ...
}

Answers


First of all:

- (void)viewWillAppear:(BOOL)animated {
    if (false == [[MyClass sharedData] getLoginStatus])
    {
        LoginViewController *loginViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"myCustomPopoverLoginVC"];
            loginViewController.modalPresentationStyle = UIModalPresentationFormSheet;
            [self presentViewController:loginViewController animated:YES completion:^{

        }];
...
    }
}

- (void)viewDidLoad
{
    // Add log here to check when its called
    -------> NSLog("Add Observer");
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLogin:) name:@"afterLogin" object:nil];
    [super viewDidLoad];
...
}

-(void)notificationLogin:(NSNotification *)notification{
    NSLog(@"OhOhOh");
}

then add another log here :

-(IBAction)login:(id)sender{
    ...
    -------> NSLog("Post notification");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"afterLogin" object:nil];
    ...
}

So you can check what called first. Then refer @Sandeep Kumar comment :)) NSNotificationCenter doesn't work in popup view(ios objC)


Need Your Help

Java preferences API throughput

java registry preferences

I'm using Java Preferences API to store window position and size of Swing application. At this moment, I'm listening to window resize/reposition events and storing the position and size every time ...

How can I get the offset of a particular row in MySQL?

php mysql where offset

I'm trying to make an image database which does not keep a consistent record of ID's. For example it might go 1,2,6,7,12, but as you can see that is only 5 rows.