views:

25

answers:

1

I have one root viewcontroller loaded by app delegate and a second one (no nib file) that should be loaded as root controller's child (i want to display its view contained in root controller's view). Where and how should i do this? Is viewDidLoad method suitable for such initialization?

- (void)viewDidLoad {   
MyViewController* pdfController = [[MyViewController alloc]init];
[self.view addSubview:pdfController.view];  
[super viewDidLoad]; }

What about releasing such an object? Should I release it in dealloc or viewDidUnload or both? where viewDidUnload/dealloc will be called?

A: 

viewDidLoad is an okay place to add your child view to the root view. You should release it at the end of viewDidLoad; pdfController will be going out of scope (so you'll be losing track of the object) and [UIView addSubview:] will retain it. If you were also keeping a reference to pdfController in an object property, you would want to release it in dealloc for that object.

Seamus Campbell