Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

iphone - How to use NSNotification

In my application there is two viewControllers as FirstViewController and DetailViewController. When tap on a table cell, it navigate to DetailViewController. In DetailViewController, I want to edit and reload the FirstViewController's table view

How 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];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
-(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 {

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...