Adding an iPhone Tablet Controller Icon

I am adding viewController to TabBarController. When I add ViewController from custom class and Nib its icon is not displayed in the tabBar.

If I initialize this, the icon is not displayed.

viewController = [[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController"  bundle:[NSBundle mainBundle]];

      

But a generic viewController mechanism is created.

viewController = [[UIViewController alloc] initWithNibName:nil  bundle:nil];

      

This is where we add the image and title.

viewController.title = @"Quiz";
viewController.tabBarItem.image = [UIImage imageNamed:@"magnifying-glass.png"];

      

How can I get the icon displayed on boot from the NIB?

+2


source to share


2 answers


You can add a call to the installer tabBarItem.image

to your custom control method viewDidLoad

:

@implementation FlashCardViewController
//...
- (void)viewDidLoad {
    [super viewDidLoad];

    self.tabBarItem.image = [UIImage imageNamed:@"magnifying-glass.png"];
}
//...
@end
      



Edit: Ok, so it 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];
}
      

+1


source


Why do you go to [NSBundle mainbundle] to initialize FlashCardViewController? Usually you just pass at zero - as per your working example ...



0


source







All Articles