警告窗口层次结构 [英] Warning about window hierarchy

查看:148
本文介绍了警告窗口层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的调试器中有这样的警告,这是什么意思?

I having a warning like this in my debugger, What does this mean?

警告:尝试提供< RootViewViewController:0x134ce9c0> on< MovieViewController:0xa967290>其视图不在窗口层次结构中!

我还将 MovieViewController 设为在Storyboard中的初始视图控制器,我也在使用ARC。

I also make the MovieViewController as the initial view controller in Storyboard, I am also using ARC.

注意:当我添加两个 [super viewDidLoad]时,这不会出现; viewDidLoad 的最低部分中间code> 1,这是错误的。

NOTE: This doesnt appear when I add two [super viewDidLoad]; 1 in the middle in lowest part of the viewDidLoad,which is wrong.

这是我执行 MovieViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"gameopening" ofType:@"m4v"];
    self.moviePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:moviePath]];
    [self.moviePlayer play];

    // Create and configure AVPlayerLayer
    AVPlayerLayer *moviePlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer];
    moviePlayerLayer.bounds = CGRectMake(0, 0, 1024, 768);
    moviePlayerLayer.position = CGPointMake(515,385);
    moviePlayerLayer.borderColor = [UIColor clearColor].CGColor;
    moviePlayerLayer.borderWidth = 3.0;
    moviePlayerLayer.shadowOffset = CGSizeMake(0, 3);
    moviePlayerLayer.shadowOpacity = 0.80;

    // Add perspective transform

    [self.view.layer addSublayer:moviePlayerLayer];    

    [self performSelector:@selector(loadingView) withObject:nil afterDelay:33.0];  
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    tapGesture.numberOfTapsRequired = 1;
    [self.view addGestureRecognizer:tapGesture];

}

- (void)handleTapGesture:(UITapGestureRecognizer *)sender {

    if (sender.state == UIGestureRecognizerStateEnded) {
        UIImageView *loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 
        loadingView.image = [UIImage imageNamed:@"Load.png"];
        [self.view addSubview:loadingView];
        [self performSelector:@selector(mainV) withObject:nil afterDelay:2.0];  
    }

}
-(void)loadingView{

        UIImageView *loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];  
        loadingView.image = [UIImage imageNamed:@"Load.png"];
        [self.view addSubview:loadingView];
        [self performSelector:@selector(mainV) withObject:nil afterDelay:2.0];  

}
-(void)mainV {

        moviePlayer = nil;
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"mainViewController"];
        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:vc animated:YES completion:NULL];   
}

非常感谢帮助:)

推荐答案

视图时,会调用 viewDidLoad 方法您的ViewController加载到内存中。但到那时,视图还没有在屏幕上显示(所以它还没有添加为任何子视图其他视图窗口,又名它不在视图层次结构中。

The viewDidLoad method is called when the view of your ViewController is loaded into memory. But by that time, the view is not on screen yet (so it has not been added as a subview of any other view or window, a.k.a it is not in the view hierarchy).

您应该等待视图在屏幕上显示 MovieViewController
viewDidAppear:方法中移动代码,而 viewDidLoad ,你应该没问题。

You should wait for the view to be on screen to present your MovieViewController. Move your code in the viewDidAppear: method instead and viewDidLoad and you should be OK.

这篇关于警告窗口层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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