0
votes

I have a UINavigation controller. The viewController contents is as follows

[RestaurantViewController, MenuViewController, ProductViewController]

In ProductViewController I call

self.navigationController?.present(sideViewController, animated:true, completion:nil)

This presents the view controller as expected. Now when I call self.dismiss/self.presentingViewController.dismiss from within sideViewController, the original NavigationController Resets to

[RestaurantViewController]

Why is this? I just want to dismiss and be returned to the presenting viewController

1
Test in a small clean project and you will see that the behavior you describe is not normal. Therefore you are doing something else that causes the navigation controller to pop/unwind back to the RestaurantViewController. But you have not described what that is; only you can find out.matt
The problem must lie in what happens after controller is dismissed. You must have called popToRootViewController some where or you are using someone's library that calls this popToRootViewControllerThe Mach System
@matt You were right, I was calling some code that declared viewControllers being called inside a viewWillAppear function rather than a viewDidLoad therefore was resetting it. Thanksmwild

1 Answers

0
votes

Why not just present the controller from ProductViewController using

self.present(sideViewController, animated:true, completion:nil)

Then dismiss using

self.dismiss(animated: true , completion: nil)

Other than that there could be many things that could cause your issues. If you want a navigation controller on the sideViewController then create a navigation controller and set sideViewController as the rootviewcontroller and present the navigation controller.

let nav = UINavigationController(rootViewController: //SideViewController)
self.present(nav, animated: true, completion: nil)