Friday, 15 June 2012

ios - viewDidLoad not called when modifying navigation stack -



ios - viewDidLoad not called when modifying navigation stack -

i removing views navigation stack, creating new controller (from storyboard) , adding controller in stack. problem viewdidload never called (checked breakpoint) when new controller instantiated. ideas why happening? code below.

[self.collectionview.collectionviewlayout invalidatelayout]; uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil]; pfgridpageviewcontroller *nc = [storyboard instantiateviewcontrollerwithidentifier:@"gridpagevc"]; [self.navigationcontroller setviewcontrollers:nil]; nsarray *new = [[nsarray alloc] initwithobjects:nc, nil]; [self.navigationcontroller setviewcontrollers:new];

temporary solution

as can see in give-and-take ian in accepted answer, modifying navigation stack bad idea. i've come temporary solution while work on better. utilize poptoroot , pushvc , modify stack 1 time remove vc @ index 0.

[self.navigationcontroller poptorootviewcontrolleranimated:no]; uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil]; pfgridpageviewcontroller *nc = [storyboard instantiateviewcontrollerwithidentifier:@"gridpagevc"]; [self.navigationcontroller pushviewcontroller:nc animated:no]; nsmutablearray *controllers = [nsmutablearray arraywitharray:self.navigationcontroller.viewcontrollers]; [controllers removeobjectatindex:0]; [self.navigationcontroller setviewcontrollers:controllers];

viewdidload called when access .view property of uiviewcontroller. seems unconventional way of doing [self.navigationcontroller pushviewcontroller:nc animated:no].

if sure implementation (i'm not), add together in line somewhere , phone call viewdidload you:

[nc view];

ios objective-c

No comments:

Post a Comment