I’m creating a Tabbed Application, and I’m having some trouble getting my icons to show up on the tabs. I’ve compared my code to a previous example I had worked on out of the book, and it seems to match, but the icons in the new application just show up as blank squares. I’ve tried to include all the relevant code without all the fiddly bits, but if you’d like to see more, just ask, and I’ll edit more in as the need dictates. I’ve already checked that the case is identical on the imageNamed:string and the icon name.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
... // initializers for ViewControllers 1-3, which are custom viewControllers
// that have the tab properties set in (void)viewDidLoad
globalUINavigationController = [[UINavigationController alloc] initWithNibName:
@"DemoTabbedFourthViewController" bundle:nil];
globalUINavigationController.title = NSLocalizedString(@"Fourth", @"Fourth");
globalUINavigationController.tabBarItem.image = [UIImage imageNamed:@"fourth.png"];
UIViewController *viewController4 = [[DemoTabbedFourthViewController alloc]
initWithNibName:@"DemoTabbedFourthViewController" bundle:nil];
[globalUINavigationController pushViewController:viewController4 animated:YES];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,
viewController3, globalUINavigationController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
I’m using the globalUINavigationController as my example, because if I can get that one working, I should be able to get the others working based on it. If you have any questions or comments about the code, let me know. I’m new to Objective C and iPhone App development, and I’ll take all the help I can get.
I think the problem is that you initialize the UINavigationController with a nib file. I actually never tried this. You should first initialize the ViewController and than add this to the NavigationController in its init message. Also you have to set the title on the content view controller, not on the navigation controller, as the navigation controller asks its topViewController for the title it should display.
I haven’t compiled the code below so there might be some missing commas or something like that, but it should give you an idea of what I meant.
If this doesn’t fix the problem, it might be because your icon files are regular images. Just the alpha channel of the image is used for tab bar items.
//EDIT: In this case, have a look at this question: UITabBarItem images just appear as a grey block