【发布时间】:2013-10-17 20:09:46
【问题描述】:
我试图让视图控制器在第一次运行并且仅在第一次时呈现InitialViewController。然而,它与这条消息一起出现:
警告:尝试呈现不在窗口层次结构中的视图!
那我的代码有什么问题?
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL hasRunBefore = [defaults boolForKey:@"FirstRun"];
if (!hasRunBefore) {
[defaults setBool:YES forKey:@"FirstRun"];
[defaults synchronize];
UIViewController * InitialViewViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"view2"];
[self presentViewController:InitialViewViewController animated:YES completion:NULL];
}
else
{
NSLog (@"Not the first time this controller has been loaded");
}
【问题讨论】:
-
您正在运行的这段代码在哪里?它应该在您应用的第一个呈现的 ViewController 中。
标签: ios objective-c uiviewcontroller