xcode 关闭通过 Popup 呈现的 ViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15001178/
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:49:37  来源:igfitidea点击:

Dismiss ViewController that is presented via Popup

iosxcodeipadpopupuipopovercontroller

提问by sj.cleaver

So i am creating an ipad recipe based app using storyboards. Just to give you an idea of the structure of my program here is the flow of View controllers:

所以我正在使用故事板创建一个基于 ipad 食谱的应用程序。只是为了让您了解我的程序结构,这里是视图控制器的流程:

ViewController --Modally--> PreviewViewController --Modally--> RecipeViewController --Popup--> IngredientsViewController

ViewController --Modally--> PreviewViewController --Modally--> RecipeViewController --Popup-->成分视图控制器

All of this has been done in storyboarding. I created the IngredientsViewControllerand have linked it up to the RecipeViewControllerto be displayed as a popup, which works fine. However i want to be able to dismiss the IngredientsViewControllerprogramatically (because i've implemented voice command features). The problem is i can't seem to access the IngredientsViewControllerto dismiss it. (appologies i can't yet post any pictures).

所有这些都是在故事板中完成的。我创建了IngredientsViewController并将其链接RecipeViewController到要显示为弹出窗口的 ,这很好用。但是我希望能够以IngredientsViewController编程方式关闭(因为我已经实现了语音命令功能)。问题是我似乎无法访问IngredientsViewController以关闭它。(抱歉,我还不能发布任何图片)。

I am using the following code to present the IngredientsViewControllerprogramatically (from within RecipeViewController):

我正在使用以下代码以IngredientsViewController编程方式(从 内RecipeViewController)呈现:

[self performSegueWithIdentifier:@"ingr" sender:nil];

Which works fine to display the popup, but i cant dismiss it. I've tried to access it through the hierarchy of view controllers but cannot seem to find it, i would assume that it would be at the top of the stack, but apparently not? I've tried things like:

显示弹出窗口效果很好,但我不能忽略它。我试图通过视图控制器的层次结构访问它,但似乎找不到它,我认为它会在堆栈的顶部,但显然不是?我试过这样的事情:

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

Again this was called from within RecipeViewController. But that simply dismisses the RecipeViewControllerand not the IngredientsViewControllerthat is being presented by popup.

这又是从内部调用的RecipeViewController。但这只是忽略了弹出窗口呈现的RecipeViewController而不是IngredientsViewController

Just to be clear the IngredientsViewControlleris not a UIPopoverController, it is a normal viewControllercreated in storyboard, and its segue style is popup linked to a button in the RecipeViewController.

需要明确的IngredientsViewControllerUIPopoverController,它不是,它是viewController在情节提要中创建的普通样式,并且它的转场样式弹出链接到RecipeViewController.

Any help would be greatly appreciated. Thanks!

任何帮助将不胜感激。谢谢!

采纳答案by Rakesh

UIPopoverController *popOver = (UIPopoverController *)self.presentedViewController;
[popOver dismissPopoverAnimated:YES];

This should do the trick if your destination view controller is a UIPopoverController

如果您的目标视图控制器是一个 UIPopoverController

回答by lolkyfan

Have you tried presentViewController:animated:completion:instead of performSegueWithIdentifier:?

你试过presentViewController:animated:completion:代替performSegueWithIdentifier:吗?