How can I setup a view controller to refresh the fields in the view only it is pushed on a navigation controller and releases the objects when it is popped from navigation controller views.
My goal is that for a view controller:
- Refresh display only when it is pushed on the navigation controller stack
- releases data when it is popped from the navigation controller stack
- reuse the controller as much as possible (to eliminate xib files loading/unloading overhead)
Are there any delegate methods for viewWillBePushed: and viewWillBePopped:?
Example
Let's say I have three layers of views:
Movies (MovieListController)
--> Movie Basic Info (MovieInfoController)
--> Movie Credits (MovieCreditsController)
Assume we have a class Movie to represent each movie.
Here, I want to only have three UIViewControllers, one instance of each in the runtime of the program. So I can reuse the same MovieInfoController for different movies and similarly MovieCreditsController.
However, I would also like MovieInfoController to only update its view fields (e.g. title, release date, etc) only when it is pushed on the stack. Implementing the display in viewWillAppear will force it to update fields even when MovieCreditsController is popped.
Also, I want MovieInfoController to release its reference to Movie, when it is popped, and any potentially large object (e.g. cover image). Implementing this logic in viewWillDisappear will cause it to release the data when it is pushing MovieCreditsController on the stack.
Is there reasonable? Am I going about it the wrong way?