gpt4 book ai didi

iphone - 如何使用 NSNotification

转载 作者:可可西里 更新时间:2023-11-01 03:44:46 25 4
gpt4 key购买 nike

在我的应用程序中有两个 View Controller ,分别是 FirstViewControllerDetailViewController。当点击表格单元格时,它会导航到 DetailViewController。在 DetailViewController 中,我想编辑并重新加载 FirstViewController 的 TableView

如何使用 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 {

}

关于iphone - 如何使用 NSNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com