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
Dismiss ViewController that is presented via Popup
提问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 IngredientsViewController
and have linked it up to the RecipeViewController
to be displayed as a popup, which works fine. However i want to be able to dismiss the IngredientsViewController
programatically (because i've implemented voice command features). The problem is i can't seem to access the IngredientsViewController
to dismiss it. (appologies i can't yet post any pictures).
所有这些都是在故事板中完成的。我创建了IngredientsViewController
并将其链接RecipeViewController
到要显示为弹出窗口的 ,这很好用。但是我希望能够以IngredientsViewController
编程方式关闭(因为我已经实现了语音命令功能)。问题是我似乎无法访问IngredientsViewController
以关闭它。(抱歉,我还不能发布任何图片)。
I am using the following code to present the IngredientsViewController
programatically (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 RecipeViewController
and not the IngredientsViewController
that is being presented by popup.
这又是从内部调用的RecipeViewController
。但这只是忽略了弹出窗口呈现的RecipeViewController
而不是IngredientsViewController
。
Just to be clear the IngredientsViewController
is not a UIPopoverController
, it is a normal viewController
created in storyboard, and its segue style is popup linked to a button in the RecipeViewController
.
需要明确的IngredientsViewController
是UIPopoverController
,它不是,它是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:
吗?