views:

99

answers:

2

Is it safe to assume that an attribute, namely fetchedResultsController, of chatViewController, an instance of a subclass of UITableViewController, is always nil when viewDidLoad is called, assuming that it's set to nil in viewDidUnload? Phew!

If that's the case, then I see no immediate need to redefine the accessor function like in the Xcode example application CoreDataBooks. I'd rather just put all that code in viewDidLoad instead of in a separate function because that's the only place I'll use it.

+1  A: 

You have to assume that viewDidLoad can be called multiple times. If there is a memory warning sent, your view controller will unload the view from memory, and the next time it is needed viewDidLoad will be called.

Aaron Saunders
Just to be clear, `viewDidLoad` won't be called multiple times consecutively.
Shaggy Frog
That makes sense. So, I can assume that if I set `fetchedResultsController` in `viewDidLoad` and `nil` it in `viewDidUnload`, then I won't be unnecessarily setting it again in `viewDidLoad`? In other words, `viewDidUnload` is always called before another call of `viewDidLoad`, correct?
MattDiPasquale
A: 

viewDidLoad is called after your view is loaded. Whether or not fetchedResultsController is nil or not depends on how the viewController is initialized. You could do something like this from the view that creates the view you're talking about. For Example, the code below would set fetchedViewController before viewDidLoad is called:

    RecipeDetailViewController *detailViewController = [[RecipeDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    detailViewController.fetchedResultsController = fetchedResultsController;

    [self.navigationController pushViewController:detailViewController animated:animated];
    [detailViewController release];

That said, then nil'ing fetchedResultsController in viewDidUnload would ensure that it's nil.

Jordan
Cool. Thanks. I think your last sentence there has answered my question. That's good to know! :)
MattDiPasquale