- This snippet will
- Add an Observer in the viewController class
- Post a notification to observer
- Trigger an function from a selector specified in the Observer
- Language
- Objective-C
- Tags
- NSNotificationCenter Notifications defaultCenter
- Favorited By
Simple NSNotificationCenter example
1 // Add an observer that will respond to loginComplete
2 [[NSNotificationCenter defaultCenter] addObserver:self
3 selector:@selector(showMainMenu:)
4 name:@"loginComplete" object:nil];
5
6
7 // Post a notification to loginComplete
8 [[NSNotificationCenter defaultCenter] postNotificationName:@"loginComplete" object:nil];
9
10
11 // the function specified in the same class where we defined the addObserver
12 - (void)showMainMenu:(NSNotification *)note {
13 NSLog(@"Received Notification - Someone seems to have logged in");
14 }
Comments
Sign in to leave a comment.

