我试图搜索这个,但找不到任何完美的解决方案。 我的应用程序有自定义动画视图和两个侧抽屉。我也有自定义navigationController,它有滑动顶部栏。从appDelegate我将第一个控制器设置为rootViewController,然后推送ViewController(即带有动画的mainViewController)。 然后试图推动第二个控制器。从第二个控制器我可以到按钮Click上的第三个控制器或rootViewController。 当我在使用popToViewController从secondController返回后尝试转到第二个viewController时,应用程序崩溃。
我在appdelegate将rootViewController设置为:
let profileViewController = mainStoryboard.instantiateViewController(withIdentifier: "LoadingDataView") as! LoadingDataView
self.navigationController = SDNavigationController(rootViewController: profileViewController);
self.navigationController.navigationBar.isHidden=true;
self.window!.rootViewController = self.navigationController
self.window!.makeKeyAndVisible()
将ViewController(mainController)推送为:
if( app.navigationController.viewControllers.count < 2){
let profileViewController=mainStoryboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
app.navigationController?.pushViewController(profileViewController, animated: true);
}else{
let profileViewController=mainStoryboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
app.navigationController?.pushViewController(profileViewController, animated: false);
let emptyView = UIViewController();
app.navigationController?.pushViewController(emptyView, animated: false);
app.navigationController.popViewController(animated: true);
}
然后将第二个viewController推送为:
let tutorialView=myStory.instantiateViewController(withIdentifier: "BookmarksDetails") as! BookmarksDetails;
self.navigationController!.pushViewController(tutorialView, animated: true);
从第二个viewController返回:
let testController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as! ViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
testController.isOpenLeftDrawer = true
appDelegate.window?.rootViewController = testController
self.navigationController?.popToRootViewController(animated: true)
当我尝试从viewController(mainController)转到secondViewController时,应用程序崩溃。
答案 0 :(得分:1)
你为什么这样做 -
app.navigationController.popViewController(animated: true);
只需按这里即可使用pop ViewController代码。