在我的应用程序中有两个 viewController,分别是 FirstViewController
和 DetailViewController
.当点击表格单元格时,它会导航到 DetailViewController
.在 DetailViewController
中,我想编辑并重新加载 FirstViewController
的表格视图
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
如何使用 NSNotification
解决这个问题?
How can I use NSNotification
for this problem?
这是我要实现的方法 NSNotification
东西
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];
}
-(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 {
}
这篇关于如何使用 NSNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!