gpt4 book ai didi

ios - self.tabBarController dismissViewControllerAnimated 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:33 31 4
gpt4 key购买 nike

我的应用程序中有一个 UITabBarController。

我想从一个选项卡显示另一个 UIViewController。

所以我在 ViewControllerA(这是 tabviewcontroller 中的一个选项卡)中写道:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *chooseTemplateController = [storyboard instantiateViewControllerWithIdentifier:@"myController"];
[self.tabBarController presentViewController:myController animated:NO completion:nil];

这很好地展示了 MyViewController。

但是,我怎样才能关闭 MyViewController?

我读了很多问题需要打电话:

[self.tabBarController dismissViewControllerAnimated:NO completion:nil];

但是 - 我从哪里调用它?我从 MyViewController 尝试过 - 但由于它不是 UITabBar 的一部分,因此 self.tabBarController 为空。

我从 Storyboard而不是 appDelegate 初始化 UiTabBarController,我想保持这种状态。

最佳答案

使用presented viewController的presentingViewController属性

objective-C

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

swift

presentingViewController?.dismissViewControllerAnimated(false, completion: nil)

你也可以使用这个速记版本(我不建议你这样做,但你会经常看到它)

objective-C

[self dismissViewControllerAnimated:NO completion:nil];

swift

dismissViewControllerAnimated(false, completion: nil)


Dismissing a Presented View Controller

关于ios - self.tabBarController dismissViewControllerAnimated 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14732622/

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