簡體   English   中英

警告窗口層次結構

[英]Warning about window hierarchy

我的調試器中有這樣的警告,這是什么意思?

Warning: Attempt to present <RootViewViewController: 0x134ce9c0> on <MovieViewController: 0xa967290> whose view is not in the window hierarchy!

我還將MovieViewController作為Storyboard中的初始視圖控制器,我也使用ARC。

注意:當我添加兩個[super viewDidLoad];時,這不會出現[super viewDidLoad]; viewDidLoad最低部分中間1,這是錯誤的。

這是我對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];   
}

幫助將不勝感激:)

當ViewController的view加載到內存中時,將調用viewDidLoad方法。 但到那時, view還沒有在屏幕上顯示(因此它沒有被添加為任何其他viewwindowsubview ,也就是說它不在視圖層次結構中)。

您應該等待視圖在屏幕上顯示您的MovieViewController 移動你的代碼在viewDidAppear:方法和viewDidLoad ,你應該沒問題。

viewDidLayoutSubviews可用於此目的。 它早於viewDidAppear。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM