我有这种情况,我在我的应用程序中使用自定义UITabBar
它在设备和模拟器上的ios4中运行良好。
但是使用xcode 4.2和ios5 sdk运行相同的代码无法正常工作,因为当我在此行上设置自定义tabBarController
的视图控制器时,应用程序崩溃了:
tabBarController.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];
以下是我创建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;
}
here是一个很小的工作示例。
非常感谢您的帮助。