PDA

View Full Version : Creating Tab & Nav. controllers / Memory Management




CMT
Jul 31, 2010, 11:47 AM
What is the best option for creating nav controllers inside a tab bar controller:

1.Keep the tab as ivar:

@interface AppDelegate ... {
UITabBarController *tabController;
... window;
}
...
@implementation AppDelegate

-(void)applicationDidFinishLaunching {
tabController = [[UITabBarController alloc] init];

// Create nav controllers, put them on tabController and release them

[window addSubview:tabController.view];
[window makeKeyAndVisible];
}

-(void)dealloc {
[tabController release];
[super dealloc];
}


2.Keep everything as ivars:

@interface AppDelegate ... {
UITabBarController *tabController;
UINavController *firstNavController, secondNavController;
... window;
}
...
@implementation AppDelegate

-(void)applicationDidFinishLaunching {
tabController = [[UITabBarController alloc] init];

// 'alloc] init];' nav controller

// add them to tab controller

[window addSubview:tabController.view];
[window makeKeyAndVisible];
}

-(void)dealloc {
[firstNavController release];
[secondNavController release];
[tabController release];
[super dealloc];
}


Are there any advantages on keeping everything as ivars? Or the top controller only is enough, so it can be accessed later? Or maybe, I'm completely wrong and there is no need to keep an view controller ivar? :P

Thanks!