0

I have this case where I am using a custom UITabBar in my application.
It is working great in ios4 on both device and simulator.

But running the same code using xcode 4.2 and ios5 sdk wont work, as the app is crashing when I am setting the view controllers of my custom tabBarController on this line:

tabBarController.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];

Here is how I am creating the tabBar:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    tabBarController = [[MBCustomTabBarController alloc] init];

    home=[[Home alloc] initWithNibName:@"Home" bundle:nil];
    UINavigationController *nc1=[[UINavigationController alloc] initWithRootViewController:home];

    live=[[Live alloc] initWithNibName:@"Live" bundle:nil];
    UINavigationController *nc2=[[UINavigationController alloc] initWithRootViewController:live];

    report=[[Report alloc] initWithNibName:@"Report" bundle:nil];
    UINavigationController *nc3=[[UINavigationController alloc] initWithRootViewController:report];


    //custom tabbar items
    MBCustomTabBarItem *firstItem = [[MBCustomTabBarItem alloc] initWithTitle:@"headlines" image:[UIImage imageNamed:@"HOME-.png"] tag:0];
    MBCustomTabBarItem *secondItem = [[MBCustomTabBarItem alloc] initWithTitle:@"live" image:[UIImage imageNamed:@"NEWS-.png"] tag:1];
    MBCustomTabBarItem *thirdItem = [[MBCustomTabBarItem alloc] initWithTitle:@"report" image:[UIImage imageNamed:@"REPORT-.png"] tag:2];


    [firstItem setImage:[UIImage imageNamed:@"HOME.png"] forState:UIControlStateSelected];
    [secondItem setImage:[UIImage imageNamed:@"NEWS.png"] forState:UIControlStateSelected];
    [thirdItem setImage:[UIImage imageNamed:@"REPORT.png"] forState:UIControlStateSelected];

    nc1.tabBarItem=firstItem;
    nc2.tabBarItem=secondItem;
    nc3.tabBarItem=thirdItem;

    [firstItem release];
    [secondItem release];
    [thirdItem release];


    tabBarController.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];
    [nc1 release];
    [nc2 release];
    [nc3 release];
    tabBarController.customTabBar.frame = CGRectMake(0, 480 - 49, 320, 49);
    tabBarController.customTabBar.backgroundColor = [UIColor clearColor];
    tabBarController.customTabBar.itemWidth = 320 / [self.tabBarController.viewControllers count];


    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

And here is a small working example.

Your help is highly appreciated.

astazed
  • 649
  • 1
  • 10
  • 24

1 Answers1

0

Never mind, I've totally changed my approach and used this answer to build my custom tabBar. And it is working fine under ios5.

Community
  • 1
  • 1
astazed
  • 649
  • 1
  • 10
  • 24