尝试呈现* on *,其视图不在窗口层次结构中 [英] Attempt to present * on * whose view is not in the window hierarchy

查看:131
本文介绍了尝试呈现* on *,其视图不在窗口层次结构中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序委托(我创建了一个名为showLoginView的函数)模态视图控制器。但是每当我尝试调用它,我在XCode中收到一个警告:

I'm trying to make a modal view controller in my app delegate (I created a function called showLoginView). But whenever I try to call it I get a warning in XCode:

Warning: Attempt to present <PSLoginViewController: 0x1fda2b40> on <PSViewController: 0x1fda0720> whose view is not in the window hierarchy!

以下是方法代码:

- (void)showLoginView
{
    PSLoginViewController *loginViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:@"PSLoginViewController"];
    [self.window.rootViewController presentViewController:loginViewController animated:NO completion:nil];
}

如何将视图添加到窗口层次结构?

How can I add the view to the window hierarchy? Or maybe I'm doing something very wrong?

推荐答案

您不能从appDelegate显示模态视图控制器。您需要从任何viewController当前显示全屏显示模式ViewController。换句话说,你需要把这个代码放到你的根视图控制器,或者任何一个你想显示模态vc从...

You can't display a modal view controller from the appDelegate. You need to display a modal ViewController from whichever viewController is currently displaying full-screen. In other words, you need to put that code into your root view controller, or whichever one you want to display the modal vc from...

想要使用方法presentModalViewController来呈现模态。您可以在模态vc上设置属性,例如:

Also, you'll want to use the method "presentModalViewController" to present the modal. You can set properties on the modal vc such as:

vC.modalPresentationStyle = UIModalPresentationFormSheet;
vC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:vC animated:YES];

这篇关于尝试呈现* on *,其视图不在窗口层次结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆