Ios 在打开ViewController之前,如何刷新视图的内容?

Ios 在打开ViewController之前,如何刷新视图的内容?,ios,uiviewcontroller,uinavigationcontroller,viewdidload,popviewcontroller,Ios,Uiviewcontroller,Uinavigationcontroller,Viewdidload,Popviewcontroller,我有两个viewcontroller。第一个视图控制器包括地图和注释,当我触摸注释时,第二个视图出现。在第二个视图中,我触摸删除按钮。因此,必须先刷新我的第一个视图的内容,然后才能执行此代码:[self.navigationController popViewControllerAnimated:YES] 我需要调用viewdiload方法或从第二个视图刷新上一个视图的内容。-(void)视图将显示:动画 不确定其是否在[self.navigationController popViewCont

我有两个
viewcontroller
。第一个视图控制器包括地图和注释,当我触摸注释时,第二个视图出现。在第二个视图中,我触摸删除按钮。因此,必须先刷新我的第一个视图的内容,然后才能执行此代码:
[self.navigationController popViewControllerAnimated:YES]
我需要调用
viewdiload
方法或从第二个视图刷新上一个视图的内容。

-(void)视图将显示:动画

不确定其是否在[self.navigationController popViewControllerAnimated:YES]之前调用;但是在你看到风景之前。调用以在其中重新加载地图的注释

另外,请确保调用ViewWillooksuper

如果两个视图不在同一个数据对象中工作,则需要一个委托将数据发送回。

-(void)视图将显示:动画

不确定其是否在[self.navigationController popViewControllerAnimated:YES]之前调用;但是在你看到风景之前。调用以在其中重新加载地图的注释

另外,请确保调用ViewWillooksuper


如果两个视图不在同一个数据对象中工作,则需要一个委托将数据发送回。

如Andy所说,您可以使用委托模式,也可以使用
NSNotificationCenter
。我个人使用
NSNotificationCenter

要使用通知中心,您需要向视图控制器类添加观察者。当您弹出视图时,您会向中心发送通知,比如说您的通知是
update
。当您使用
update
通知中心时,中心会告诉任何类有
update
运行方法。。。。这很简单

[[NSNotificationCenter defaultCenter]postNotificationName:@“更新”对象:nil]

检查此答案的完整代码:

如Andy所说,您可以使用委托模式,也可以使用通知中心。我个人使用
NSNotificationCenter

要使用通知中心,您需要向视图控制器类添加观察者。当您弹出视图时,您会向中心发送通知,比如说您的通知是
update
。当您使用
update
通知中心时,中心会告诉任何类有
update
运行方法。。。。这很简单

[[NSNotificationCenter defaultCenter]postNotificationName:@“更新”对象:nil]

检查此答案的完整代码:
由于viewcontroller中存在任何对象更改,因此将调用ViewWillApear或ViewDidApear,但如果要从另一个viewcontrollerB更改viewcontrollerA,则需要NSNotificationCenter从viewcontrollerA调用函数

您始终可以使用NSNotificationCenter更新父视图控制器

在父视图控制器上,放置以下内容:

//since child view controller calls turnItOff, notification center calls function "turnButtonCountinuesOff"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnButtonCountinuesOff) name:@"turnItOff" object:nil];
//connect to parent UI view controller calls notification turnItOff.
[[NSNotificationCenter defaultCenter] postNotificationName:@"turnItOff" object:nil];
TurnButtonCountNuesOff是父视图控制器的功能

在您的子视图控制器上,放置以下内容:

//since child view controller calls turnItOff, notification center calls function "turnButtonCountinuesOff"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnButtonCountinuesOff) name:@"turnItOff" object:nil];
//connect to parent UI view controller calls notification turnItOff.
[[NSNotificationCenter defaultCenter] postNotificationName:@"turnItOff" object:nil];

希望有帮助。

将调用ViewWillApear或ViewDidApear,因为viewcontroller中存在任何对象更改,但如果要从另一个viewcontrollerB更改viewcontrollerA,则需要NSNotificationCenter从viewcontrollerA调用函数

您始终可以使用NSNotificationCenter更新父视图控制器

在父视图控制器上,放置以下内容:

//since child view controller calls turnItOff, notification center calls function "turnButtonCountinuesOff"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnButtonCountinuesOff) name:@"turnItOff" object:nil];
//connect to parent UI view controller calls notification turnItOff.
[[NSNotificationCenter defaultCenter] postNotificationName:@"turnItOff" object:nil];
TurnButtonCountNuesOff是父视图控制器的功能

在您的子视图控制器上,放置以下内容:

//since child view controller calls turnItOff, notification center calls function "turnButtonCountinuesOff"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnButtonCountinuesOff) name:@"turnItOff" object:nil];
//connect to parent UI view controller calls notification turnItOff.
[[NSNotificationCenter defaultCenter] postNotificationName:@"turnItOff" object:nil];
希望能有帮助