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?
In Swift 4:
Whatever code you are writing in
viewDidLoad
, try to add that inviewWillappear()
. I think this will solve your problem.You shouldn't call viewDidLoad method manually, Instead if you want to reload any data or any UI, you can use this:
Whenever you want to reload the data and refresh the interface, you can call self.loadData()
This might be a little late, but did you try calling
loadView()
?At any point call when you want to reload viewController's View or any view