tags:

views:

476

answers:

2

In one of the views I launch programmatically, I see 5 different calls to 'loadView/viewdidLoad' but I don't understand why this many are getting called. Can someone explain to me the mechanics behind this?

I launch the view in the parent UIViewController (part of a TabBar + NavigationBar application) instance in the following manner:

MainEditController *editController = [[MainEditController alloc] initWithNibName:@"MainEditView" bundle:nil];        
[self.navigationController pushViewController:editController animated:YES];      
[editController release];

I then log MainEditController's viewDidLoad and loadView methods (and invoking their respective super methods).

The 'MainEditView' nib contains 3 items: -File's Owner (of type MainEditController), -First Responder (of type UIResponder) -View (of type UIView)

The view outlet is connected to the File's Owner and the View has no elements in it. What I intend to do is add several subs views to the main view and display one of the subviews based on a specific condition.

I thought both viewDidLoad and loadView would get called as many views (1 in this case) within the controller but that doesn't seem to be a valid assumption.

+2  A: 

I'm not sure if this is what you're seeing but a navigation controller will release views that are not currently visible to regain memory if a low memory warning is received by the app. When the view becomes visible again the view is recreated, which calls loadView.

CynicismRising
+2  A: 

Is your loadView method calling [super loadView]? If not, the view property is likely not being set up properly, and so the next time .view is accessed, it tries to load it again.

Stab in the dark, but without the loadView method, it's hard to narrow down what might be the problem.

NilObject
the documentation for loadView states: Your custom implementation of this method should not call super.
Can Berk Güder