Search code examples
iosswiftios13

View pops from navigation controller stack when tapped


I have a popover view which is simply a stack of UIButtons.

The popover is presented from a view controller (Records) which is itself inside a NavigationController.

I need the buttons in popover view to be able to push other views on top of the navigation stack. Here's how I prepare the segue for the popover in the Records view controller:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "popoverSegue" {
            let dest = segue.destination as! PopoverViewController
            dest.navController = navigationController
            dest.modalPresentationStyle = .popover
            dest.popoverPresentationController?.barButtonItem = addButton
            dest.popoverPresentationController?.delegate = self
        }
    }

Then inside the popoverViewController I got a bunch of IBAction functions where I need to push other views on top of the navController that was set above.

let editor = EditorViewController(nibName: "EditorViewController", bundle: nil)
navController?.pushViewController(editor, animated: true)

This kina works and the editor view shows up with a nav bar and all, but as soon as I tap on the view or try to scroll, it just gets dismissed.

How can I prevent that dismiss thing? I did try setting isModalInPresentation. It didn't work for me.


Solution

  • Answering, as per OP's comments...

    The proper approach is to have your "popover" controller tell the presenting controller to push a new VC onto the navigation stack.

    This can be done in a few different ways, but most commonly by using either the protocol/delegate pattern or with closures.