gpt4 book ai didi

objective-c - 关闭 2 个模态视图 Controller

转载 作者:行者123 更新时间:2023-12-01 16:58:35 24 4
gpt4 key购买 nike

我有一个基本的模态视图 Controller 。然后我创建第二个:

FieldReportViewController *fieldReport = [self.storyboard instantiateViewControllerWithIdentifier:@"fieldReportView"];
[self presentModalViewController:fieldReport animated:YES];

从那里,我调用第三个 View Controller :
ScoutingReportViewController *scoutingReport = [self.storyboard instantiateViewControllerWithIdentifier:@"ScoutView"];
[self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:scoutingReport animated:YES];

现在我想回到第一个 View Controller 。我试过(这是当前显示的 View Controller ):
-(IBAction)doneBtn
{
//[self.parentViewController dismissModalViewControllerAnimated:YES]; //removed

[self dismissModalViewControllerAnimated:NO]; //added

[[NSNotificationCenter defaultCenter] postNotificationName:@"CloseAllModalViews" object:nil userInfo:nil]; //added

}

在中间/s View Controller 中,我在 viewDidLoad 中添加了一个观察者:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dismissModals:)
name:@"CloseAllModalViews"
object:nil];

和方法:
-(void) dismissModals:(id)sender
{
[self dismissModalViewControllerAnimated:NO];
}

按下时,它什么也不做。它不否认任何观点。

任何想法我怎样才能让它工作?

编辑:弄清楚它为什么会崩溃;我忘记了我在 IB 的完成按钮上添加了一个 segue。这会导致内存问题并导致崩溃。

编辑 2:这会将两个 View Controller 解散回基本/第一个 View Controller 。它没有给我任何动画。我可以在没有动画的情况下关闭当前的 VC,并在没有动画的情况下关闭中间的 VC,但我在过渡前会短暂看到中间的 VC。如果可能的话,我希望有一个从当前 VC 到基本 VC 的动画。

最佳答案

我以前做过,我不得不使用 UINotificationCenter 来关闭中间 View 。当您按下 doneBtn 时,发布通知。在推送其他 View 之前,添加一个以您的dismissModal 作为操作的观察者。如果您删除动画,它应该看起来就像您刚刚回到原始 View 。

在您看来,您想自动关闭:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dismissModals:)
name:@"CloseAllModalViews"
object:nil];

把它放在你的 doneBtn 方法中:
[[NSNotificationCenter defaultCenter] postNotificationName:@"CloseAllModalViews" object:nil userInfo:nil];

关于objective-c - 关闭 2 个模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9420989/

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