When my view controller is first presented, I want it to potentially update a cache that provides the data for that view. However, when the user taps the back button from a deeper view controller to return to this view controller, I don’t want to update the cache again.
Which event should I be using?
- in
init, I don’t have all the parameters I need yet. viewWillAppearwill be fired every time the view will appear.viewDidLoadwill be fired every time the view has been loaded from the nib, which I believe could happen a second time if there’s a memory warning. (Or is this wrong?) Since this is not a memory resident cache, it seems the wrong place to handle this.- having the caller call something extra is inelegant, if there’s a built-in way to handle this.
To clarify, this is not a memory resident cache. This is parsing an XML file to binary. The binary is loaded and unloaded in viewDidLoad and viewDidUnload. This is a prerequisite for that step, making sure the binary is up-to-date prior to it being loaded.
Using
initmay work, but I would recommend a simple subclass ofUINavigationController. Create a new method calledsetRootTableViewController:(UITableViewController *)controller, or something like it. In the method implementation call this:reloadDatawill call all of your delegate and data source methods, and use them to update the table. If you want a special method call on your table view controller instead, you could change the method declaration tosetRootTableViewController:(CustomTableViewController *)controller(or whatever your custom table controller is called), and replace thereloadDataline with one that calls that method.Then, in your app delegate, instead of creating a
UINavigationControllerand adding your custom view controller, create one of these, and call this method to add the first view.However, if you are using a nib to set the
rootViewController, you can just overrideinitWithRootViewController:(UIViewController *)controller, as I imagine that is what the nib will call to set the first view in the stack:Hope this helps!