不鼓励在分离的视图控制器上呈现视图控制器(使用 SWRevealViewController)

Presenting view controllers on detached view controllers is discouraged (with SWRevealViewController)

我正在更改 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>.

如何解决?

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

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

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

solution

    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)