self.tabBarController dismissViewControllerAnimated不起作用 [英] self.tabBarController dismissViewControllerAnimated doesn't work
问题描述
我的应用程序中有一个UITabBarController。
I have a UITabBarController in my application.
我想从一个标签中呈现另一个UIViewController。
I would like to present from one tab, another UIViewController.
所以我写了 ViewControllerA
(这是tabviewcontroller中的一个标签):
So I wrote in ViewControllerA
(which is a tab in the tabviewcontroller):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *chooseTemplateController = [storyboard instantiateViewControllerWithIdentifier:@"myController"];
[self.tabBarController presentViewController:myController animated:NO completion:nil];
这很好地显示了MyViewController。
This shows MyViewController nicely.
但是,我该怎么解雇MyViewController?
However, how can I dismiss MyViewController?
我读了很多我需要打电话的问题:
I read in many questions that I need to call:
[self.tabBarController dismissViewControllerAnimated:NO completion:nil];
但是 - 我从哪里调用它?我尝试从MyViewController - 但由于它不是UITabBar的一部分,self.tabBarController为null。
However - where do I call it from? I tried from MyViewController - but since it's not part of the UITabBar, self.tabBarController is null.
我从故事板而不是appDelegate初始化UiTabBarController我想保持这种状态。
I initialize the UiTabBarController from storyboard and not from appDelegate and I would like to leave it that way.
推荐答案
使用提供的viewController的 presentsViewController
property
Use the presented viewController's presentingViewController
property
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
Swift
Swift
presentingViewController?.dismissViewControllerAnimated(false, completion: nil)
你也可以使用这个速记版本(我不建议你这样做,但你会经常看到它)
You can also use this shorthand version (I don't recommend you do, but you will see it often)
[self dismissViewControllerAnimated:NO completion:nil];
Swift
Swift
dismissViewControllerAnimated(false, completion: nil)
参见< br>
驳回呈现的视图控制器
这篇关于self.tabBarController dismissViewControllerAnimated不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!