How to use NSNotification
11,370
-(void)viewDidLoad {
[NSNotificationCenter defaultCenter];
NSNotification* notification = [NSNotification notificationWithName:@"MyNotification" object:self];
[[NSNotificationCenter defaultCenter] postNotification:notification];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (objFirstViewController) name:@"MyNotification" object:nil];
}
-(IBAction) save{
[[NSNotificationCenter defaultCenter] postNotificationName:MyNotification object:sender];
//this will go to where you implement your selector objFirstViewController.
}
-(void)objFirstViewController:(NSNotification *)notification {
}
Author by
smartsanja
Updated on June 08, 2022Comments
-
smartsanja almost 2 years
In my application there is two viewControllers as
FirstViewController
andDetailViewController
. When tap on a table cell, it navigate toDetailViewController
. InDetailViewController
, I want to edit and reload theFirstViewController
's table viewHow can I use
NSNotification
for this problem?Here's the method I want to implement
NSNotification
stuff-(IBAction) save{ strSelectedText=theTextField.text; [NSNotificationCenter defaultCenter]; NSNotification* notification = [NSNotification notificationWithName:@"MyNotification" object:self]; [[NSNotificationCenter defaultCenter] postNotification:notification]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (objFirstViewController) name:@"MyNotification" object:nil]; [self.navigationController popViewControllerAnimated:YES]; }