Smipple is shutting down Nov 30, 2017. Some features are currently disabled.
Profile image for Johan Sanden Sounden
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
NSNotificationCenter Notifications defaultCenter
Favorited By
Profile image for Johan Sanden Profile image for Thiti Sununta Profile image for Pablo Ezequiel

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 }


Profile image for Pablo Ezequiel PabloEzequiel 2016-08-08

very useful snippet