0

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

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

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

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

这是我的实现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];   
}

帮助将不胜感激:)

4

2 回答 2

2

当您的 ViewController 加载到内存中时,将调用该viewDidLoad方法。view但是到那时,view还没有出现在屏幕上(所以它还没有被添加为subview任何其他的viewor window,也就是它不在视图层次结构中)。

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

于 2012-10-03T09:01:11.217 回答
0

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

于 2013-02-22T03:08:09.807 回答