我在AppDelegate
中使用以下代碼在應用程序中顯示彈出窗口,當選擇按鈕時,我最終會將其移至標籤超鏈接,但僅測試當前。嘗試呈現*其視圖不在窗口層次結構中
let storyboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("test") as! ViewController
let popOverVC = UIStoryboard(name:"Main", bundle: nil).instantiateViewControllerWithIdentifier("sbPopUpID") as! PopUpViewController
storyboard.addChildViewController(popOverVC)
popOverVC.view.frame = storyboard.view.frame
storyboard.view.addSubview(popOverVC.view)
popOverVC.didMoveToParentViewController(storyboard)
self.window?.rootViewController?.presentViewController(storyboard, animated: true, completion: nil)
我第一次選擇按鈕,此正常工作,但是在隨後的所有按鈕,按以下錯誤顯示。
2016-10-28 11:27:40.551 testfordeeplinks[20496:104536] Warning: Attempt to present on whose view is not in the window hierarchy!
感謝雅各,將返回以下錯誤:從「UIViewController的」 低迷現狀,只有解開自選,你的意思是使用「!」? – ScoopMatt
我沒有看到錯誤,所以我猜你只是忘了粘貼它? :P –
來自「UIViewController」的下變量只能解開可選項,是不是要使用'!'? – ScoopMatt