webmagnets webmagnets - 1 year ago 79
Swift Question

How can I completely reload a view so that viewDidLoad gets run again?

I would like to reload my view so that

redoes all of its work. How can I do that in Swift?

Answer Source

viewViewDidLoad and viewWillAppear are part of the view controller lifecycle and are called automatically by iOS after your UIViewController got instantiated and before the view appears on the screen. You can call them anywhere in your view controller class, but that's not at all good practice and I would never recommend you to do so!

If you have code that you want to be executed at multiple times during the lifetime of your view controller, put it into separate methods and call these from viewDidLoad and from the other parts in your code where you need them.

You can read more about the view controller life cycle in Apple's documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download