Hi to all,
I'm a newbie of Obj-C and Cocoa. After spending some days trying to build my first app using a TabBarController with IB I realize to make it programmatically (not all...).
Now I create the UITabBar at runtime (applicationDidFinishLaunching) and I made 4 xib for four view associated withe tabbar items.
Xib File's Owners are 4 different ViewController. Every Xib file contains a UITabBarItem associated with the tabBarItem outlet of the UIViewController (the file's owner)
The problem is that when the application loads, only the first item in the tabbar is visible, with the associated view, but the others not.
When I push where I suppose there's the other item, the tabbar item title is displayed with the associated view correctly.
How can I show all the tabbaritems when I load the application??
This is my application delegate code:
Code:
@synthesize window;
@synthesize tabBarController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:4];
// Creo i 4 view controller
FeaturedViewController *featured = [[FeaturedViewController alloc] initWithNibName:@"FeaturedView" bundle:nil];
SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
HelpViewController *help = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil];
SettingsViewController *settings = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
// li aggiungo all'array locale di controller
[controllers addObject:featured];
[controllers addObject:second];
[controllers addObject:help];
[controllers addObject:settings];
[featured release];
[second release];
[help release];
[settings release];
tabBarController.viewControllers = controllers;
// [[tabBarController viewControllers] addObjectsFromArray:controllers];
[controllers release];
// Aggiungo il tab controller alla window
tabBarController.selectedIndex = 0;
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
}
This is a screenshot when I first run the application (as you see, there's only one tabbaritem and not four...)