IOS - Disable View Cache in View Controller
The correct way to do this would be to perform your actions in viewDidAppear
. Initialisation code that you write in viewDidLoad
is called only once. But in viewDidAppear
you can refresh your view's content every time the view is added to the window. The controller is retained in the memory for performance reasons. Removing it would hamper that factor.
Here is a stack overflow post that explains the different view*
callbacks in good detail.
Related videos on Youtube
Wassim Taher
Updated on November 23, 2022Comments
-
Wassim Taher over 1 year
I am pushing and popping from one view to the other within my App. The view is being retained in the memory so when you hit the "Back" button after pushing a view, the same screen that was before you pushed the view is retained.
For some reason, I will need to reload the parent view after popping from a child view. I need to display different content based on the actions the user taken when they were redirected to the child view.
I am using UINavigationController to navigate from one view to the other. I need it so I can easily go back and forth within the different views of the App.
-
Nandeep Mali over 11 yearsWhy not use
viewDidAppear:
to modify the view? The things that you do inviewDidLoad
, which happens only once, can be done here instead. -
Wassim Taher over 11 yearsThis is a great tip that I wasn't aware of. I am going to try it out later on today and if it works out I will come back and accept your answer. Can you please post this as an answer meanwhile? Thanks!
-