0

I defined a custom initWithCoder method because I'm trying to make custom tool bar items. I have 5 view controllers in my storyboard, each with a custom class. They are all child classes of the initial view controller's class. The main problem is that instead of just changing the image of one classes tab bar item, it changes the image of each tab bar item that is pressed. Also, the images aren't changed to the unselected tab bar item image when the tab bar item is unselected. Each child classes view controller receives the same init method. My main problem is how do I make it so that each class, regardless of child or parent, receives a different init method?

 -(id)initWithCoder:(NSCoder *)aDecoder

{
        NSLog(@"First");
        if (self = [super initWithCoder:aDecoder]) 

    {
            NSLog(@"Second");
            [[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"RedStar2.png"] 
            withFinishedUnselectedImage:[UIImage imageNamed:@"Star3.png"]];
            //instead of just changing the image of the class's tab bar item, it changes the image of all
            classes tab bar items
            [[self tabBarItem] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor
            redColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
      }
        return self;
} 

The keywords "first" and "second" are both called 5 times when the application is run. Each view controller has a custom class.

user1626438
  • 133
  • 5
  • 14

1 Answers1

0

If you want a different image for each tab, you've got to duplicate this method 5 times in each of your subclasses, instead of doing the same work in the "common ancestor" -- the superclass.

Cyrille
  • 25,014
  • 12
  • 67
  • 90