ios - how to custom back button in storyboard -


i create 1 application has 3 viewcontroller names : (viewcontroller,viewcontroller2,viewcontroller3) in viewcontroller exist 1 button checking file in document folder or download it.for example first check file if file exist in document folder go viewcontroller3 else go viewcontroller2 , download it.

so viewcontroller2 download , has uilable & uiprogress show download status.if file dont exist in page downloaded , go viewcontroller3.

so viewcontroller3 show file. (these pages connect push segue image in bottom)

when go page , click button return pervious page right?? when click on button in first page , file dont exist , downloading in second page finished download go page 3.now want when click on button in page 3 go page 1 no page 2!!!!

i work in storyboard.

enter image description here

you can achieve intercepting button event in viewcontroller3 , using unwindsegues. check out william jockusch's reply question how intercept button event.

to use unwind segues in particular case need to:

1) in viewcontroller1 create method such as

- (ibaction)unwindtothisviewcontroller:(uistoryboardsegue *)unwindsegue {     nslog(@"rolled back"); } 

2) in storyboard zoom out, ctrl-drag viewcontroller3 "exit" green box on left contained in viewcontroller3 scene (along red box first responder , controller view's subviews). popup window show, asking ibaction want connect unwind segue to, , should able select unwindtothisviewcontroller action created. create unwind segue.

3) select scene box unwind segue , give id, such "unwindtostart"

4) finally, in viewcontroller3 class, override method viewwilldisappear follows:

-(void) viewwilldisappear:(bool)animated  {     if ([self.navigationcontroller.viewcontrollers indexofobject:self]==nsnotfound)         [self performseguewithidentifier:@"unwindtostart" sender:self];     [super viewwilldisappear:animated]; } 

this intercept button event , unroll viewcontroller1, , you're go.

edit: unwind segues supported on ios 6 , later, if need functionality on earlier versions of ios think way manually remove viewcontroller2 navigationcontroller stack in viewcontroller3's viewdidload. following code should do:

- (void)viewdidload {        nsmutablearray *viewcontrollers = [nsmutablearray arraywitharray:self.navigationcontroller.viewcontrollers];     for(uiviewcontroller* vc in self.navigationcontroller.viewcontrollers)     {         if ([vc iskindofclass:[viewcontroller2 class]]) {             [viewcontrollers removeobject:vc];             break;         }     }     self.navigationcontroller.viewcontrollers = [nsarray arraywitharray:viewcontrollers];     // additional setup after loading view. } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -