I have a popupViewController with a UIView as below. The UIView view changes by pressing a button below the UIView. The UIView then changes to one of the coloured view on the right side of diagram. I have a button on each view that I would like to dismiss/ close the popupView to return back to the main ViewController view (ARSCNView), but I can't seem to get it to work? I can actually close the popUpView via the 'close' button which is on the PopUpViewController.
I have tried to call the function that closes the popupview from within one of the views to the right but it does nothing. Any help would be great.
The popupView is presented as below, from the Main ViewController:
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! popupViewController
self.addChildViewController(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParentViewController: self)
Do I have to dismiss for example: 1.FirstViewController (Blue) 2.MasterViewController (white) 3.PopUpViewController
to get to the ARSCNView?
CodePudding user response:
One solution is to use delegate as follows below:
In your childrens view. (example)
protocol ChildrenViewControllerDelegate {
func closeAll()
}
class ChildrenViewController: UIViewController {
var delegate : ChildrenViewControllerDelegate?
@IBAction func close(_ sender: UIButton) {
delegate?.closeAll()
}
...
and in your parent view, set the ChildrenViewControllerDelegate and:
class ParentViewController: UIViewController, ChildrenViewControllerDelegate
func closeAll() {
self.navigationController?.popViewController(animated:true)
}
// Set/pass the delegate on children:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.chindrenVc = segue.destination as? ChildrenViewController
self.childrenVc?.delegate = self
}