Friday, 15 February 2013

iphone - Setting Finished TabBar images when using storyboards? -



iphone - Setting Finished TabBar images when using storyboards? -

i working on application mass of ui setup via storyboard in xcode. 1 thing want specify "finished" images uitabbaritems on tabbar rather default "stencilled" images can access via interface builder.

my question best place this, doing in awakefromnib needs done when things unarchived storyboard, unsure if should using initwithcoder: instead, best 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"]; } homecoming 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 initwithcoder: called @ start of unarchiving objects nibs (contained in storyboard) when outlets , actions not yet hooked up. understand awakefromnib called @ end of unarchiving process , signals viewcontroller ready use. feeling depends on want do, although using awakefromnib might prove less problematic not going nail issues outlets , actions not yet hooked up.

edit:

let me rephrase this, situations utilize initwithcoder: apposed awakefromnib , vice versa?

it seems you've answered own question in paragraph before edit.

the documentation states that

when object receives awakefromnib message, guaranteed have outlet instance variables set.

so if have access iboutlet ivars in initialisation code, have in awakefromnib method.

although prefer initwithcoder: in cases when not need access outlets because proper initialiser method objects beingness decoded nscoding protocol according nscoding documentation:

initwithcoder: instructs object initialize info in coder provided; such, replaces other initialization method , sent 1 time per object

as side note though, not create much of difference , in cases when have access outlets in initialization code, not implement both awakefromnib , initwithcoder: sake of simplicity. if outlets involved implement awakefromnib , initialisation there.

iphone objective-c cocoa-touch awakefromnib initwithcoder

No comments:

Post a Comment