whose view is not in the window hierarchy

whose view is not in the window hierarchy

在ViewController的viewDidLoad方法里执行如下操作:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self presentViewController:[[TestController alloc] init] animated:YES completion:nil];
}

以上只是会出现whose view is not in the window hierarchy错误的一种情况,错误日志如下:

Warning: Attempt to present <TestController: 0x15bd5f550> on <ViewController: 0x15beb12f0> whose view is not in the window hierarchy!

看下警告,原因是ViewController自己还没加载到Window上呢,就用他去present下一个控制器导致的。

也就是说当一个控制器自己还没有完全创建成功的时候做这种操作都会出现类似问题。

猜你喜欢

转载自blog.csdn.net/morris_/article/details/79901767