iOS using protocols and closing modally presented view controller

50 views Asked by At

I have Navigation controller and a ViewController. let's call it MainVC. Now I am opening some ViewControllers in following way

MainVC --(Modally presented)---> VC1 ---(Modally presents)->>VC2

Now VC2 gets some data and throws it data in below given way to VC1

if let del = self.delegate{
             //Closing Current view controller 
            self.dismiss(animated: true, completion: nil) 
            del.onDataSuccessfullyFetched()


        }

However the Protocol is defined as

protocol DelegateOnDialogDismiss {

    func onDataSuccessfullyFetched()

}

Similarly VC1 Throws its data back to MainVC and gets dismissed like shown in above code. And then delegated method in MainVC pushes a new viewController to NavigationView like so ...

let popOverHouseHoldInfo = UIStoryboard(name: "Main",bundle: nil).instantiateViewController(withIdentifier: "idHouseHoldInfoVC") as! HouseHoldInfoViewController
                  self.navigationController?.pushViewController(popOverHouseHoldInfo, animated: true)

Problem:

The MainVC is calling that function to push new ViewController in NavigationView but it is not getting happen. I do not know why. But everything is working as expected until the delegates tries to Push newViewController but failed.

My assessment: I think the main culprit is following line as we are dismissing Modally presented viewControllers :

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

Please help me. I do not know what is the main problem in this workflow.

0

There are 0 answers