I have tried to search for this, but can't find any perfect solution. My app has custom animating views and both side drawers.I also have custom navigationController which has sliding top bar.From appDelegate I'm setting first controller as rootViewController and then pushing ViewController(i.e. mainViewController with animations). then trying to push second controller. From second controller I can go to either third controller or rootViewController on button Click. And app crashes when I tried to go to second viewController after getting back from secondController using popToViewController.
I'm setting rootViewController at appdelegate as:
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()
Pushing ViewController(mainController) as:
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);
}
Then pushing second viewController as:
let tutorialView=myStory.instantiateViewController(withIdentifier: "BookmarksDetails") as! BookmarksDetails;
self.navigationController!.pushViewController(tutorialView, animated: true);
getting back from second viewController as:
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)
app crashes when I tried to go to secondViewController from viewController(mainController).
Why you are doing this -
app.navigationController.popViewController(animated: true);
Just only push and don't use the pop ViewController code here.