从app delegate调用Storyboard场景

时间:2016-10-19 10:12:21

标签: ios objective-c appdelegate scene

我想从appDelegate调用故事板场景[storyboard ID : MyScene]

我已经搜索并尝试了很多关于堆栈溢出的答案!但找不到有效的解决方案。

我试过的一个代码,

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController *sc= (UIViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MyScene"];

[self.window.rootViewController presentViewController:sc animated:YES completion:nil];

1 个答案:

答案 0 :(得分:1)

尝试使用此代码调用一些延迟。

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ 

// Your code for presenting 

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController *sc= (UIViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MyScene"];

[self.window.rootViewController presentViewController:sc animated:YES completion:nil];

});