The Swift Coder
The Swift Coder

Reputation: 442

Dismissing Modal ViewControllers And Reinstantiating Parent

In my application, a view is presented Modally over another view. In particular, the modally-presented view, which is actually embedded in a NavigationController, is causing issues. After several attempts of opening the view, I receive this error, and the modal presentation is halted.

00 AppName[48335:1973353] [Presentation] Attempt to present <UINavigationController:
0x7b640000e100> on <UINavigationController: 0x7b640000a000> (from <AppName.ViewController: 
0x7b600007b800>) which is already presenting <UINavigationController: 0x7b640000d200>.

Is there any way I can dismiss my Modal viewController, and also instantiate the parent ViewController? I need to reinstantiate the Parent controller from the child, but I believe that in doing so I am causing the issue of nesting.

Upvotes: 0

Views: 528

Answers (1)

sonle
sonle

Reputation: 9045

You can not present multiple controllers above a controller. Dismiss your current presenting controller after present another one. There are several ways to do it:

1: Using NotificationCenter to post an event when you need to dismiss the current presenting controller.

2: Using completion block while dismissing current controller.

dismiss(animated: true) {
   //do something here
}

Upvotes: 2

Related Questions