尝试在视图不在窗口层次结构中的 UIViewController 上显示 UIViewController [英] Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy

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

问题描述

刚开始使用 Xcode 4.5,我在控制台中收到此错误:

Just started using Xcode 4.5 and I got this error in the console:

警告:尝试呈现 <完成视图控制器:0x1e56e0a0 > on 其视图不在窗口层次结构中!

Warning: Attempt to present < finishViewController: 0x1e56e0a0 > on < ViewController: 0x1ec3e000> whose view is not in the window hierarchy!

视图仍在呈现,应用程序中的一切正常.这是 iOS 6 中的新功能吗?

The view is still being presented and everything in the app is working fine. Is this something new in iOS 6?

这是我用来在视图之间切换的代码:

This is the code I'm using to change between views:

UIStoryboard *storyboard = self.storyboard;
finishViewController *finished = 
[storyboard instantiateViewControllerWithIdentifier:@"finishViewController"];

[self presentViewController:finished animated:NO completion:NULL];

推荐答案

你从哪里调用这个方法?我在尝试在 viewDidLoad 方法中显示模态视图控制器时遇到了问题.我的解决方案是将此调用移动到 viewDidAppear: 方法.

Where are you calling this method from? I had an issue where I was attempting to present a modal view controller within the viewDidLoad method. The solution for me was to move this call to the viewDidAppear: method.

我的假设是,视图控制器的视图 不在窗口视图层次结构中,在它被加载时(当 viewDidLoad 消息被发送),但在它被呈现后它在窗口层次结构中(当 viewDidAppear: 消息被发送时).

My presumption is that the view controller's view is not in the window's view hierarchy at the point that it has been loaded (when the viewDidLoad message is sent), but it is in the window hierarchy after it has been presented (when the viewDidAppear: message is sent).

注意

如果您确实在 viewDidAppear: 中调用了 presentViewController:animated:completion:,您可能会遇到一个问题,即模式视图控制器总是在每当视图控制器的视图出现(这是有道理的!)所以呈现的模态视图控制器永远不会消失......

If you do make a call to presentViewController:animated:completion: in the viewDidAppear: you may run into an issue whereby the modal view controller is always being presented whenever the view controller's view appears (which makes sense!) and so the modal view controller being presented will never go away...

也许这不是展示模态视图控制器的最佳位置,或者可能需要保留一些额外的状态,以允许展示视图控制器决定是否应该立即展示模态视图控制器.

Maybe this isn't the best place to present the modal view controller, or perhaps some additional state needs to be kept which allows the presenting view controller to decide whether or not it should present the modal view controller immediately.

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

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