我通过推送显示ViewController时遇到问题。我有这段代码,可以很好地处理现在。但我需要改变它来推动。我尝试使用self.navigationController?。pushViewController(slideMenuController,动画:真(,但这对我不起作用。
func navToRecord() {
let mainViewController = kMainStoryboard.instantiateViewController(withIdentifier: "NQTPrivateOfficeViewController") as! NQTPrivateOfficeViewController
let leftViewController = kMainStoryboard.instantiateViewController(withIdentifier: "NQTLeftViewController") as! NQTLeftViewController
let nc = odrexNavigation(rootViewController: mainViewController)
let slideMenuController = EVTSlideMenuController(mainViewController: nc, leftMenuViewController: leftViewController)
slideMenuController.automaticallyAdjustsScrollViewInsets = true
mainViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Завершить", comment: "finishOdrex"), style: .plain, target: self, action: #selector(action))
self.present(slideMenuController, animated: true, completion: nil)
UIApplication.shared.keyWindow?.makeKeyAndVisible()
}
你可以试试
let nav = UINavigationController(rootViewController: self)
UIApplication.shared.keyWindow?.rootViewController = nav
nav.pushViewController(slideMenuController, animated: true)
顺便说一句,不要指望这条线
self.navigationController?.pushViewController(slideMenuController, animated: true)
如果你在其中执行它的 VC 没有包装在导航控制器中,则起作用,因为self.navigationController?将为零
推送转换用于将视图控制器推送到导航控制器的堆栈上。如果从中运行该代码的视图控制器不在导航堆栈上,则self.navigationController
将为 nil,因此可选的链接调用self.navigationController?.pushViewController()
将失败,并且该行将被忽略。
您需要重构情节提要,以便视图控制器嵌入到导航控制器中。(我记得界面生成器中有一个"嵌入>导航控制器"菜单项,它将更改情节提要,以便选定的视图控制器是导航控制器的根视图控制器。
self.nc.pushViewController(slideMenuController, animated: true(