Navigation Controller is nil, though embedded in a view controller

523 Views Asked by At

Storyboard

As you can see, my navigation controller is embedded in the root view controller. In this view controller, I have a subview, and at one point, I push the popover onto the view controller. For some reason, I cannot use navigationController.popViewController(animated: true) because the navigation controller is nil(by printing the value to the debug console). How can I fix this?

2

There are 2 best solutions below

0
ielyamani On BEST ANSWER

Use dismiss(animated flag: Bool, completion: (() -> Void)? = nil). Call it from your popover view controller:

self.dismiss(animated: true) 
0
Anton On

if you present your popover from ViewController

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

you can dismiss it in popover

self.dismiss(animated: true) 

and if you push your popover to your navigation controller by

self.navigationController?.pushViewController(popover, animated: true)

you can dismiss your popover using

self.navigationController?.popViewController(animated: true)