I am trying to call a method within an uiview from AppDelegate using the NSNotificationCenter to no avail..
AppDelegate.m
[[NSNotificationCenter defaultCenter] postNotificationName:@"ProcessDidComplete" object:items];
Then via MainStoryboard, the main view is loaded which controller class is MainViewController
in MainViewController.h viewDidLoad i have
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ProcessDidComplete:) name:@"ProcessDidComplete" object:nil];
and then the method
- (void) ProcessDidComplete:(NSNotification *)pNotification
but it never gets called.
Thanks for any help!
just change a way..
First add observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ProcessDidComplete:) name:@"ProcessDidComplete" object:nil];
Then Post Notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"ProcessDidComplete" object:items];
Finally remove in viewWillDisappear
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ProcessDidComplete" object:nil];
Your code looks okay, which makes me wonder where in your app delegate you post the notification?
If you post the notification before you add the observer in the view controlller, then the notification will never be received. Can you not send the message to the main view controller directly, i.e., as a property, rather than using notifications?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With