In your first view controller (where you need to be notified of some event) you implement code to register and remove notification.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
- (void)viewDidLoad { [super viewDidLoad]; // add an observer to listen for the notification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomeAction) name:@"DisplayModalControllerNotification" object:nil]; } // this action fires when we receive a notification - (void)doSomeAction { // do something here when the notification is received } // be sure to remove the notification observer - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } |
Now with the code above in place in your first view controller you will simply call it whenever you need it with this line of code which posts the notification:
1 2 |
// post a notification [[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayModalControllerNotification" object:nil]; |