0

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).

Arasuvel
  • 2,971
  • 1
  • 25
  • 40
sagar ss
  • 23
  • 7
  • The last line in your "Pushing viewController(mainController)" makes no sense. `app.navigationController` is wrapped (`?`) in the push but not in the pop. If it indeed is optional, this shouldn't compile. Also, that last line, popping is the opposite of pushing, why are you pushing an empty view without animation, and instantly popping the stack with animation. – Sti Oct 04 '17 at 07:03
  • I have to create empty viewController for animating two viewControllers at same time. – sagar ss Oct 04 '17 at 07:19

1 Answers1

2

Why you are doing this -

app.navigationController.popViewController(animated: true);

Just only push and don't use the pop ViewController code here.

Aditya Srivastava
  • 2,630
  • 2
  • 13
  • 23