gpt4 book ai didi

ios - 如何呈现 TabBarController 模态

转载 作者:行者123 更新时间:2023-11-28 19:05:32 25 4
gpt4 key购买 nike

从一个 View ( LoginTesteInicial ) 我可以转到两个 tabBarControllers,但是当我运行代码时,它崩溃并出现以下错误: Attempt to present <UITabBarController: 0x8a4a870> on <LoginTesteInicial: 0x8a46970> whose view is not in the window hierarchy!

这是我来自 LoginTesteInicial.m 的代码:

UITabBarController *vc;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

vc = [[UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil] instantiateViewControllerWithIdentifier:@"TabBarSemLogin"];
} else {

vc = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"TabBarSemLogin"];
}

[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

[self presentViewController:vc animated:YES completion:nil];

最佳答案

您的问题的答案是,当调用 -viewDidLoad 时, View Controller 的 View 不在 View 层次结构中。您需要等到 View 被放入 View 层次结构中。这可以在 -viewWillAppear:-viewDidAppear: 中完成。


您收到的“对开始/结束外观转换的调用不平衡”警告是因为 View Controller 在被另一个 View Controller 替换之前尚未完全加载。为避免该警告,您可以使用 -performSelector:withObject:afterDelay: 在下一个运行循环中安排当前 View Controller 。

- (void)viewDidAppear:(BOOL)animated
{

[self performSelector:@selector(showTabBarController) withObject:nil afterDelay:0.0];
}

- (void)showTabBarController
{
UITabBarController *vc;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
vc = [[UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil] instantiateViewControllerWithIdentifier:@"TabBarSemLogin"];
} else {
vc = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"TabBarSemLogin"];
}

[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:vc animated:YES completion:nil];
}

关于ios - 如何呈现 TabBarController 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20789586/

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