ios - Amending UINavigationController viewControllers stack before animation -
ios - Amending UINavigationController viewControllers stack before animation -
i have app can customize products varying degrees. in cases options split 2 views, while in other cases first step isn't necessary.
what treat products same , force first customization step view controller navigation controller stack, allow view controller decide whether or not step necessary. if not necessary want apply default options product , skip (before transition animation) step 2 while not allowing user first step.
the normal uinavigationcontroller.viewcontrollers
stack may when @ step 2:
[listview (root)] -> [customizestep1] -> [customizestep2]
but want apply default values product , amend view controller stack that:
[listview (root)] -> [customizestep1] ----- becomes ----- [listview (root)] -> [customizestep2]
what i've tried utilize code in customizestep1
view controller:
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; if (shouldskiptostep2) { uinavigationcontroller *navcontroller = self.navigationcontroller; // move straight step 2 uistoryboard *storyboardloader = [uistoryboard storyboardwithname:@"main" bundle:nil]; uiviewcontroller *customizestep2vc = [storyboardloader instantiateviewcontrollerwithidentifier:@"customizestep2"]; // replace current view contoller nsmutablearray *viewhierarchy = [nsmutablearray arraywitharray:navcontroller.viewcontrollers]; [viewhierarchy removeobject:self]; [viewhierarchy addobject:customizevc]; // apply new viewcontroller stack [navcontroller setviewcontrollers:viewhierarchy animated:no]; } }
if take @ navigation controller's viewcontrollers
array after has been set, looks expected.
when doing this, entire functionality of uinavigationcontroller breaks. customizestep1
view controller still animates in nonfunctional. tapping button still shows customizestep1
. trying interact view controller crashes app. (it works expected if view controller displayed without sliding transition, though.)
the customizestep1
view controller still animates in, after transition ends snaps on show customizestep2
. other works intended.
so, question if there improve place add together code amend view controller stack on navigation controller?
i need wait until view controller has been added navigation controller, otherwise can't replace view controller in stack. however, need able cancel transition animation can animate in customizestep2
instead.
i appreciate if impossible, wanted check if knows way around this.
edit:
how ideally appear user
instead of viewwillappear:
, utilize viewdidappear:
called after animation finishes.
you have boolean on view controller denoting whether filled in or not:
@interface viewcontrollerone : uiviewcontroller @property (nonatomic, assign, getter = isinitiallyfilledin) bool initiallyfilledin; @end
then, when filled in, denote boolean value.
viewcontrollerone *viewcontroller = [[viewcontrollerone alloc] init]; [viewcontroller setinitiallyfilledin:yes];
now, in viewdidappear:
, check boolean value , check whether method has been launched before. if hasn't been launched before (to allow editing) , filled in, force next controller!
@interface viewcontrollerone @property (nonatomic, assign) bool hascheckedfillinstatusbefore; @end @implementation viewcontrollerone -(void)viewdidappear:(bool)animated { [super viewdidappear:animated]; if ([self isinitiallyfilledin] && ![self hascheckedfillinstatusbefore]) { // force next view controller } [self sethascheckedfillinstatusbefore:yes]; } @end
alternatively, if want display 2 view controllers @ same time, alter navigation stack:
// create instances of viewcontrollerone , viewcontrollertwo nsmutablearray *viewcontrollers = [[[self navigationcontroller] viewcontrollers] mutablecopy]; [viewcontrollers addobjectsfromarray:@[viewcontrollerone, viewcontrollertwo]]; [[self navigationcontroller] setviewcontrollers:viewcontrollers animated:yes];
note, viewcontrollerone
not have viewdidload
called if setup in method (such button title or view controller title), either have manually invoke method before setting view controllers or move setup initializer.
ios ios7 uiviewcontroller ios8
Comments
Post a Comment