Hi I'm trying to present a viewcontroller and dismiss my current modal view but this code is not working
self.dismissViewControllerAnimated(true, completion: {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("OrderViewController")
self.presentViewController(vc!, animated: true, completion: nil)
})
vice versa is not working too on completion block of presentviewcontroller
EDIT: replaced vc! to self
I think there is a mistake in your code where 'self' should be the presenting view controller to present 'vc', not 'vc' its self
Your code
Try this
hope this is helpful
you can't do that because when the UIViewController A calls the UIViewController B and the first controller is dismissed then the two controllers are nil.
You need to have a UIViewController as a base, in this case MainViewController is the base. You need to use a protocol to call the navigation between controllers.
you can do using protocol let say for example as bellow:-
In to your viewController setting Protocol :
Now in your main view controller
Code example with storyboard:
Here's a solution for Swift3
To present the ViewController
To dismiss the ViewController:
You have to get the viewController which presented the self (current ViewController). If that view controller is rootViewController that you can use as below, if not that query it based on you view controller hierarchy.