所以我有一個從ViewController segue到SecondViewController。這個segue由ViewController中的UIButton觸發,模態地呈現SecondViewController。 Segue的標識符已設置(「SegueIdentifier」),我可以從我的ViewController中以編程方式調用segue。不能調用標識符從AppDelegate
當我嘗試在我的AppDelegate中做同樣的事情時,我得到編譯器無法找到具有我設置的標識符的segue的錯誤。
let viewController = ViewController()
viewController.performSegueWithIdentifier("SegueIdentifier", sender: nil)
同樣,我字面上複製和粘貼從上述方法中的ViewController的performSegueWithIdentifier方法調用,其中我還呼籲performSegueWithIdentifier對於相同SEGUE和它的工作原理。
任何想法?
是您要的這個初始視圖推? –
@GurPreet_Singh不,我想推的視圖不是初始視圖。 – Jonas
由於您使用簡單的初始化程序創建ViewController實例,因此它不與故事板相關聯。您應該從您的碎片的主窗口訪問根視圖控制器UIApplication實例 – Paulw11