2017-09-13 93 views
-1

我使用SWRevealViewControllerSWRevealViewController零誤差

當我點擊後退按鈕獲取此錯誤

fatal error: unexpectedly found nil while unwrapping an Optional value 

我的代碼

let nesne:SWRevealViewController = self.revealViewController()//the error here 
let mainStroyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let desController = mainStroyBoard.instantiateViewController(withIdentifier: "MessageViewController") as! MessageViewController 
let newFrontViewController = UINavigationController.init(rootViewController:desController) 
nesne.pushFrontViewController(newFrontViewController, animated: true) 

回答

0

解決方案

let sw = storyboard?.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController 
self.view.window?.rootViewController = sw 

let mainStroyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let desController = mainStroyBoard.instantiateViewController(withIdentifier: "MessageViewController") as! MessageViewController 
let newFrontViewController = UINavigationController.init(rootViewController:desController) 
sw.pushFrontViewController(newFrontViewController, animated: true)