Swift: Reload a View Controller

Matt Spoon picture Matt Spoon · Jul 3, 2015 · Viewed 114.3k times · Source

I need to refresh a view controller when a certain button is tapped. Simply activating viewDidLoad() does not seem to be working for what I need to do. However, when I leave the view controller then come back to it, it seems to work perfectly?

How can I refresh/reload a view controller as if I have left it then come back to it without ever actually leaving it?

Answer

iAnurag picture iAnurag · Jul 3, 2015

Whatever code you are writing in viewDidLoad, Add that in viewWillappear(). This will solve your problem.