1

我有这个问题。我在 appDelegate 中创建了一个标签栏:

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";
} 

但是什么都没有显示,为什么?奇怪的是,如果我做同样的事情但没有导航控制器,图像就会正确显示。

4

1 回答 1

0

只需使用以下代码

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tabRoot.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabRoot.png"]];
于 2013-10-30T11:40:32.923 回答