0

我正在更改 SwRevealViewController 的 RootViewController

我的代码:

let next = self.storyboard?.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
    next.loadView()
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let viewController = mainStoryboard.instantiateViewController(withIdentifier: "MessageViewController") as! MessageViewController
    UIApplication.shared.keyWindow?.rootViewController = viewController;

    self.present(next, animated: true, completion: nil)

但我得到这个错误:

>Presenting view controllers on detached view controllers is discouraged <ios.MesajDetayViewController: 0x7f8718d646f0>.

怎么解决?

4

2 回答 2

1

解决方案

    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)
于 2017-09-13T09:24:19.807 回答
0

如果你想改变SWRevealViewContoller前视图控制器,你应该使用

let newFronViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "YourID") as! YourClass
self.revealViewController().setFront(newFronViewController, animated: false)

我可以根据您想在哪里调用它来更新我的答案。

于 2017-09-13T09:20:10.583 回答