如何使用NSNotification
在我的应用程序中有两个viewController作为FirstViewController
和DetailViewController
。 当点击表格单元格时,它将导航到DetailViewController
。 在DetailViewController
,我想编辑并重载FirstViewController
的表视图
我怎样才能使用NSNotification
这个问题?
这是我想要实现NSNotification
东西的方法
-(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 { }
从detailViewController发布通知并添加firstViewController作为观察者。
确保从viewDidUnload的观察者列表中删除fireViewController。
现在你正在添加detailViewController作为观察者。
- 如何基于一个属性对NSArray对象进行sorting
- 在目标c中调用c ++类
- 处理Sprite Kit中的中断 – 无法通过[SKAction playSoundFileNamed:中断后工作 – 获得声音效果
- RSA公钥生成 – Swift
- 为什么在我的正则expression式中有多个捕获组会崩溃我的应用程序?
- 如何手动发送UIKeyboard通知
- 在与中心点相交的给定angular度的直线相交的UIView矩形上查找CGPoint
- 如何将其他内容保存到我的UIManagedDocument文件包中?
- 在NSift中将NSUnderlineStyle.PatternDash添加到NSAttributedString?