When is viewDidLoad called?
Asked Answered
A

4

7

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.

Ablebodied answered 16/10, 2010 at 17:24 Comment(0)
H
4

viewDidLoad is called after your view is loaded. Whether or not fetchedResultsController is nil or not depends on how the viewController is initialized. For example, when creating the detailViewController, you could set its 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.

Hypodermis answered 16/10, 2010 at 20:22 Comment(1)
Cool. Thanks. I think your last sentence there has answered my question. That's good to know! :)Ablebodied
P
3

ViewDidLoad Called in These Secnarion:-

1.when we push the view controller after creating it’s object by segue or by stoary board id.

2.it called more than one in the case of creating instance more time in application and push it again and again.for example:-if you implement like coaursal(that having required to additional controller during scrolling) like that it’s need so it can called multiple times viewDidLoad.

3.it called when all memory instance (uiviewcontroller and it’s subclass instantiated) that means when our view is ready to load in memory with the address.

4.Remember only child class controller object is created..parent class object never been instantiated during normal Secnarion.

Prussian answered 28/7, 2015 at 10:59 Comment(0)
C
2

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.

Commutation answered 16/10, 2010 at 18:3 Comment(2)
Just to be clear, viewDidLoad won't be called multiple times consecutively.Potassium
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?Ablebodied
B
1

viewDidLoad is called only when view is instantiated for first time . If you're not recreating the view controller each time in your application, you'll only get it called once (and called again if you get a memory warning, and the view is nil'd out).

Brittenybrittingham answered 13/7, 2016 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.