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

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

问题描述

刚开始使用Xcode 4.5,我在控制台中出现了这个错误:

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


警告:尝试出现< finishViewController:0x1e56e0a0> on< ViewController:0x1ec3e000>其视图不在窗口层次结构中!

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:,则可能会遇到一个问题每当视图控制器的视图出现时,模态视图控制器总是被呈现(这是有意义的!),因此呈现的模态视图控制器永远不会消失......

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天全站免登陆