objective c - Working With UITabBarControllers, what's the best way to pass data when unable to use segue? -
i need return specific instance variable(an object) of thefirstviewcontroller(first tab) thesecondviewcontroller(second tab) not using segue.
what considered best practice passing data between tabs? have searched extensively , have not found clear answer. have tried think every option except using singleton. acceptable use singleton purpose? need archiving data anyways.thanks in advance.
one option have declare viewcontrollers instance variables of app delegate
add property view controller classes say(a , b) .
say wanted pass objects between view controllers can add property each:
@interface aviewcontroller : uiviewcontroller { bviewcontroller *b; } @property (nonatomic, retain) bviewcontroller *b;; @end @interface bviewcontroller : uiviewcontroller { aviewcontroller *a; } @property (nonatomic, retain) aviewcontroller *a; @end
when initialise view controller can set property object context initialised previously.
you have mentioned tab bar controller. if view controllers wired through ib have set these parameters in application delegate applicationdidfinishlaunching: method, before tab bar controller displayed:
@interface myappdelegate : nsobject <uiapplicationdelegate, uitabbarcontrollerdelegate> { aviewcontroller *aviewcontroller; bviewcontroller *bviewcontroller; ... } @property (retain) iboutlet aviewcontroller *aviewcontroller; @property (retain) iboutlet bviewcontroller *aviewcontroller; @end @implementation myappdelegate ... - (void)applicationdidfinishlaunching:(uiapplication *)application { ... aviewcontroller.b = bviewcontroller; bviewcontroller.a = aviewcontroller; [window addsubview:tabbarcontroller.view]; [window makekeyandvisible]; }
to create objects of viewcontrollers can use
uistoryboard *storyboard = [uistoryboard storyboardwithname:@"storyboard" bundle:nil]; viewcontroller* viewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"viewcontroller"];
Comments
Post a Comment