1

I have a UIViewcontroller that presents a popUpView with two buttons, cancel and continue respectively.. but the problem is that when I press the continue button, UINavigationController is not pushing to the next UIViewcontroller.. .

-- onNextButtonTapped:

 @IBAction func onOkayButtonClicked(_ sender: UIButton) {
        self.dismiss(animated: true, completion: {
            let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "nextVC") as! NextViewController
           // let nextVCNav = UINavigationController(rootViewController: nextVC)
           //self.navigationController?.pushViewController(nextVCNav, animated: true)

            
            self.navigationController?.pushViewController(nextVC, animated: true)
        })
    }

Did miss something?

dumbDev
  • 35
  • 5

2 Answers2

1

This seems like a controller chain issue. As from what I understand you must have presented the popup modally and by doing that you have moved out of the UINavigationController stack. So pushing a view from popupview controller is not an option. You can:

  1. Create a protocol, (or block implementation) that inform viewcontroller which presented popup, that particular button was clicked (something similar to UIAlertController)

  2. Make a popup as a view inside view controller and show and hide that with animation. That was you can add the action of the button of this popup to your view controller.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
0

I think the UINavigationController is not in hierarchy.
Try this

let nav = UINavigationController(rootViewController: self)
UIApplication.shared.keyWindow?.rootViewController = nav
nav.pushViewController(nextVC, animated: true)
SAIF
  • 126
  • 8