2016-10-19 50 views
0

我想打電話給一個故事板的場景從的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]; 
+0

你寫的代碼,可以嘗試使用一些延遲 – Wolverine

+0

檢查「主要」是實際存在的,你是不是在mainStoryboard獲得零值。 – mohsin

+0

感謝回覆@Wolverine,我在應用程序代理的didFinishLaunchingWithOptions中寫了此代碼。 –

回答

0

嘗試使用調用此代碼一些延遲。

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]; 

}); 
相關問題