I am working on an application where the bulk of the UI is setup via a Storyboard in Xcode. One thing that I want to do is specify "Finished" images for the UITabBarItems on a TabBar rather than the default "Stencilled" images that you can access via Interface Builder.
My question is where is the best place to do this, I am currently doing it in awakeFromNib as it needs to be done when things are unarchived from the storyboard, but I as unsure if I should be using initWithCoder: instead, which is best does it matter?
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if(self) {
UIImage *tabIn = [UIImage imageNamed:@"TAB_IN"];
UIImage *tabOut = [UIImage imageNamed:@"TAB_OUT"];
UITabBarItem *tabBarItem = [self tabBarItem];
[tabBarItem setFinishedSelectedImage:tabOut withFinishedUnselectedImage:tabIn];
[tabBarItem setTitle:@"TWO"];
}
return self;
}
OR
- (void)awakeFromNib {
[super awakeFromNib];
UIImage *tabIn = [UIImage imageNamed:@"TAB_IN"];
UIImage *tabOut = [UIImage imageNamed:@"TAB_OUT"];
UITabBarItem *tabBarItem = [self tabBarItem];
[tabBarItem setFinishedSelectedImage:tabOut withFinishedUnselectedImage:tabIn];
[tabBarItem setTitle:@"TWO"];
}
I understand that initWithCoder:
is called at the start of unarchiving objects from nibs (contained in the storyboard) when outlets and actions are not yet hooked up. I also understand that awakeFromNib
is called at the end of the unarchiving process and signals that the viewController is now ready for use. My feeling is that it really just depends on what you want to do, although using awakeFromNib
might prove less problematic as your not going to hit issues where outlets and actions are not yet hooked up.
EDIT:
Let me rephrase this, what situations would you use initWithCoder:
as apposed to awakeFromNib
and vice versa?