Reputation: 17601
I am adding a viewController to a TabBarController. When I add a ViewController from the custom class and Nib, it''s icon does not show up in the tabBar.
If I initialize like this the icon does not show up.
viewController = [[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController" bundle:[NSBundle mainBundle]];
But creating a generic viewController works.
viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
Here we add the image and title.
viewController.title = @"Quiz";
viewController.tabBarItem.image = [UIImage imageNamed:@"magnifying-glass.png"];
How can I get the icon to display if load from a NIB?
Upvotes: 2
Views: 8474
Reputation: 60150
You can add the call to the tabBarItem.image
setter inside the custom view controller's viewDidLoad
method:
@implementation FlashCardViewController
//...
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarItem.image = [UIImage imageNamed:@"magnifying-glass.png"];
}
//...
@end
Edit: OK, so that didn't work. Try:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"magnifying-glass.png"];
self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"string"
image:image
tag:0] autorelease];
}
Upvotes: 1
Reputation: 75077
Why are you passing in [NSBundle mainbundle] to the FlashCardViewController init? Usually you just pass in nil - as per your working example...
Upvotes: 0