xcode 从内部推送的 ViewController 中关闭 Modal NavigationController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13884428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:19:44  来源:igfitidea点击:

Dismiss Modal NavigationController from pushed ViewController inside

iosxcodeuinavigationcontrollerstoryboard

提问by jhilgert00

I have an iPad app and I'm using the storyboard. I'm presenting a modal view, which I wrap in a UINavigationController. It's a modal "Settings" view with it's own navigation.

我有一个 iPad 应用程序,我正在使用故事板。我正在展示一个模态视图,我将其包装在UINavigationController. 这是一个带有自己导航的模态“设置”视图。

I have a delegate setup to dismiss the modal view itself with a Done button in the Settings view which works fine, but I need to be able to dismiss it even after it has pushed another view when the user taps a setting.

我有一个委托设置,可以使用“设置”视图中的“完成”按钮关闭模态视图本身,该按钮工作正常,但即使在用户点击设置时推送另一个视图后,我也需要能够关闭它。

So, basically a "cancel" button on the right side of the Navigation bar in the pushed views. Instead of having to go back to the first "Settings" view to hit the done button.

因此,基本上是推送视图中导航栏右侧的“取消”按钮。而不必返回到第一个“设置”视图来点击完成按钮。

I've tried setting up a second delegate for the pushed view without success:

我试过为推送的视图设置第二个委托,但没有成功:

enter image description here

在此处输入图片说明

回答by rdelmar

Just add a bar button item and put this line in its action method:

只需添加一个条形按钮项并将此行放在其操作方法中:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

The presenting view controller will be the controller that presented the modal, not the navigation controller.

呈现视图控制器将是呈现模态的控制器,而不是导航控制器。