I have a universal tabbed app targetting ios 6 with 4 tabs. Almost ready to release, and I started to look at the latest and greatest ways to support iAds. After looking at the iAdSuite demo project from Apple, it seems as though using the BannerViewController to wrap my 4 UIViewControllers was the perfect solution.
And it works perfectly in so much as correctly displaying iAds.
However, since making the change my tab bar no longer has images/icons displayed. I've gone through the BannerViewController code line by line but I can't see anything that appears to be overriding the image setting.
The changes I made were:
from
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4];
to
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = @[
[[BannerViewController alloc] initWithContentViewController:viewController1],
[[BannerViewController alloc] initWithContentViewController:viewController2],
[[BannerViewController alloc] initWithContentViewController:viewController3],
[[BannerViewController alloc] initWithContentViewController:viewController4]
];
In each of my 4 view controllers I have the following code in the initWithNibName method (with the appropriate title and image names:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Library", @"Library");
self.tabBarItem.image = [UIImage imageNamed:@"96-book"];
}
return self;
}
With the original code, titles and images work as expected. With the modified code, I get the title but no image, just a black button. Has anyone come across this before?
Note I tried this out in the Apple sample app and can't get images to display there either, the sample app targets iOS5 and my app targets iOS6.
So I finally found a solution, thanks to this SO question which was sort of relevant ...
iOS Change frame of UITabBarButton in UITabBar
I removed the image setting code from the view controllers, and instead added the following lines to the AppDelegate just after the view controllers had been assigned to the UITabBar
UITabBar *tabBar = self.tabBarController.tabBar;
[[tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"253-person"]];
[[tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:@"138-scales"]];
[[tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:@"85-trophy"]];
[[tabBar.items objectAtIndex:3] setImage:[UIImage imageNamed:@"96-book"]];
And now my tab bar images are back!