我有这个问题。我在appDelegate中创建了一个tabbar:
RootViewController *controller = [[RootViewController alloc] initWithNibName:@"RootView" bundle:nil];
UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[其他控制器已初始化...]
self.tabController = [[UITabBarController alloc] init];
self.tabController.viewControllers = [NSArray arrayWithObjects:rootNavigationController,secondController,thirdController, nil];
现在,在RootViewController中,我尝试将图像分配给tabBar:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.image = [UIImage imageNamed:@"tabRoot.png"];
self.tabBarItem.title = @"Root";
}
但没有显示,为什么?奇怪的是,如果我做同样的事情但没有navigationController,图像会正确显示。
答案 0 :(得分:0)
只需使用以下代码
即可[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tabRoot.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabRoot.png"]];