我有这个问题。我在 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";
}
但是什么都没有显示,为什么?奇怪的是,如果我做同样的事情但没有导航控制器,图像就会正确显示。