【问题标题】:Call Storyboard scene from app delegate从应用委托调用 Storyboard 场景
【发布时间】:2016-10-19 18:41:31
【问题描述】:

我想从 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];

【问题讨论】:

  • 你写这段代码的地方,尝试使用一些延迟
  • 检查“Main”是否确实存在,并且您没有在 mainStoryboard 中获得 nil 值。
  • 感谢@Wolverine 的回复,我在应用委托的didFinishLaunchingWithOptions 中写了这个。
  • 尝试使用调用此代码有一些延迟。 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // 你的代码展示 });
  • 感谢@mohsin,“主要”故事板存在。

标签: ios objective-c appdelegate scene


【解决方案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];

}); 

【讨论】:

    猜你喜欢
    • 2021-11-14
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 2020-01-30
    • 1970-01-01
    • 2012-10-29
    • 2021-02-06
    相关资源
    最近更新 更多