viewDidLoad从if语句更改视图

时间:2013-03-09 22:08:45

标签: cocoa-touch

我有这段代码

if ([sessionOutput isEqualToString:@"valid"]) {
    LoggedInViewController *loggedin = [[LoggedInViewController alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:loggedin animated:YES completion:nil];
}

除非更改视图,否则我收到此消息:

 Warning: Attempt to present <LoggedInViewController: 0x717fec0> on
<ViewController: 0x8a64af0> whose view is not in the window hierarchy!

我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试将代码移至viewDidAppear: 在调用<ViewController: 0x8a64af0>时,viewDidLoad:尚未添加到视图层次结构中。

请参阅此问题:whose view is not in the window hierarchy