我试图搜索这个,但找不到任何完美的解决方案。我的应用程序有自定义动画视图和两个侧边抽屉。我也有自定义导航控制器,它有滑动顶栏。从 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);
从第二个视图控制器返回:
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 时,应用程序崩溃。