In my program, some of the transitions between viewControllers are managed programmatically via the following code:
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController
self.present(newViewController, animated: true, completion: nil)
I've been wondering how safe of a practice this is. When presentScene gets called, does it do anything to "wipe" the screen under it, or does it just stack more view on top of existing ones? If not, how does it work? Also is this the best way (in terms of performance) of managing this programatic transitions?
First of all, you don't need to create an object of UIStoaryboard
every time unless you have different name of it apart from Main
. Modification to your code:
let newViewController = self.storyBoard!.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController
Now coming to your question! When you are presenting any UIViewController
on another UIViewController
or UINavigationController
, the presented controller has no stack.
In short, you are presenting a UIViewController
modally over the presentee UIViewController
. This can happen across any UIViewController
without any relationship rules. The presenter should take care of dismissing the VC it presented.
Hope this clears your doubt.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.