我试图让视图控制器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");
}