Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabBarItems in UITabBar show after I click the item not when application launches

This application I'm writing has a problem.

I'm setting up the UITabBar in my application window and set the icons in the view files. But when i run the app, the first icons show up (because the view is loaded I guess) and the other icons do not show up until I click them.

Do i need to implement self.tabBarItem in some other method not viewDidLoad?

Thanks in advance to everyone!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    tabBar = [[UITabBarController alloc] init];

    SubscriptionsController *subscriptionsController = [[SubscriptionsController alloc] init];
    FavoritesController  *favoritesController  = [[FavoritesController  alloc] init];
    CategoriesController *categoriesController  = [[CategoriesController alloc] init];
    TagsController   *tagsController    = [[TagsController   alloc] init];
    HelpScreenController *helpScreenController  = [[HelpScreenController alloc] init];

    tabBar.viewControllers = [NSArray arrayWithObjects:
        subscriptionsController, 
        favoritesController, 
        categoriesController, 
        tagsController, 
        helpScreenController, 
        nil
        ];

    [window addSubview:tabBar.view];

    // Override point for customization after application launch.
    [window makeKeyAndVisible];
    return YES;
}

//The View

- (void)viewDidLoad {
    [super viewDidLoad];
    tabIcon = [[UITabBarItem alloc] initWithTitle:@"Abonime" image:[UIImage imageNamed:@"subscr.png"] tag:0];
    self.tabBarItem = tabIcon;
    [tabIcon release];
}
like image 742
Olsi Avatar asked Dec 11 '10 16:12

Olsi


1 Answers

I think you should set the tabBarItem property in a view controller's designated initializer (judging from your code, it must be -init for each of the controllers). In fact, the tab bar controller is smart enough to load the views on demand, that is, the tabBarItem property should be set before viewDidLoad gets sent.

Also, you seem to be leaking all the view controllers. To fix that, do the following:

SubscriptionsController *subscriptionsController = [[[SubscriptionsController alloc] init] autorelease];
like image 70
Costique Avatar answered Oct 24 '22 23:10

Costique