Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismiss second ViewController from the third ViewController

I am trying to dismiss VC b from VC c where VC c is a popover and has a button for sign out but it is not working. The structure of the flow is

VC a ----presents modally----> VC b ----presents a popover----> VC c

When the button in the popover is clicked the VC c and VC b must be dismissed so that (VC a)ViewWillAppear is called.

like image 273
bakhtiar masood Avatar asked May 13 '26 13:05

bakhtiar masood


1 Answers

Try this:

You can dismiss your presentingViewController from child view controller as follow

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

When you add a ViewController as childViewController

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

If this view controller is a child of a containing view controller (e.g. a navigation controller or tab bar controller,)

weak open var parent: UIViewController? { get }

The view controller that was presented by this view controller or its nearest ancestor.

open var presentedViewController: UIViewController? { get }

The view controller that presented this view controller (or its farthest ancestor.)

open var presentingViewController: UIViewController? { get }
like image 182
Harshal Valanda Avatar answered May 15 '26 03:05

Harshal Valanda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!