Reputation: 44886
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?
init
, I don't have all the parameters I need yet.viewWillAppear
will be fired every time the view will appear.viewDidLoad
will 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.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.
Upvotes: 2
Views: 2572
Reputation: 2441
Using init
may work, but I would recommend a simple subclass of UINavigationController
. Create a new method called setRootTableViewController:(UITableViewController *)controller
, or something like it. In the method implementation call this:
[controller.tableView reloadData];
[self pushViewController:controller animated:NO];
reloadData
will 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 to setRootTableViewController:(CustomTableViewController *)controller
(or whatever your custom table controller is called), and replace the reloadData
line with one that calls that method.
Then, in your app delegate, instead of creating a UINavigationController
and 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 override initWithRootViewController:(UIViewController *)controller
, as I imagine that is what the nib will call to set the first view in the stack:
- (id)initWithRootViewController:(UIViewController *)rootViewController {
if ((self = [super init])) {
[(CustomController *)rootViewController doSomethingSpecial];
[self pushViewController:rootViewController];
}
}
Hope this helps!
Upvotes: 1