标签栏图像未显示

时间:2013-10-30 11:34:34

标签: ios uitabbarcontroller uitabbaritem

我有这个问题。我在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,图像会正确显示。

1 个答案:

答案 0 :(得分:0)

只需使用以下代码

即可
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tabRoot.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabRoot.png"]];