ios - segueing between view controllers with navigation controller -


lets have viewcontroller 2 buttons, each segueing viewcontroller b , c (one button view b , other c).from viewcontroller c segueing viewcontroller d. viewcontrollers navigation bar view b can return a, , view d can return d->c->a. problem when segueing between view d b: segue performed in navigation bar of b retuned view d , want b return should. solution????

this can done using 2 ways far know.

1) use custom button on d controller

2) change stack of navigationcontroller i.e nsarray of self.navigationcontroller.viewcontrollers in class of d controller

use custom button

you can follows in d controller.this valid if controller rootviewcontroller of navigationcontroller.if keeping track of controller can use following also

  • (nsarray *)poptoviewcontroller:(uiviewcontroller )viewcontroller animated:(bool)animated

    - (void)viewdidload { [super viewdidload];  uibarbuttonitem *backbutton = [[uibarbuttonitem alloc]  initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:self action:@selector(goback:)];  self.navigationitem.leftbarbuttonitem = backbutton;   self.navigationitem.hidesbackbutton = yes; }  -(void)goback:(id)sender { [self.navigationcontroller poptorootviewcontrolleranimated:yes]; 

    }

change stack of navigationcontroller

this useful if want navigate particular controller.but button still displays after getting controller b,that might have see making changes.don't try change navigation stack in prepareforsegue

- (void)viewdidload {     [super viewdidload];     nsmutablearray *controllers = [nsmutablearray arraywitharray:self.navigationcontroller.viewcontrollers];     nsmutableset *controllerstoremove = [nsmutableset new];         (id viewcontroller in controllers) {             if (![viewcontroller iskindofclass:[self class]]&&![viewcontroller iskindofclass:[nrviewcontroller class]]) {                     [controllerstoremove addobject:viewcontroller];                 }         }          (id controller in controllerstoremove) {             [controllers removeobject:controller];         }     self.navigationcontroller.viewcontrollers = controllers; } 

edited code custom button

if want original button

you have use image code follow

uibutton *backbutton = [[uibutton alloc] initwithframe: cgrectmake(0, 0, 60.0f, 30.0f)];     uiimage *backimage = [[uiimage imagenamed:@"back_button_normal.png"] resizableimagewithcapinsets:uiedgeinsetsmake(0, 12.0f, 0, 12.0f)];     [backbutton setbackgroundimage:backimage  forstate:uicontrolstatenormal];     [backbutton settitle:@"back" forstate:uicontrolstatenormal];     [backbutton addtarget:self action:@selector(goback:) forcontrolevents:uicontroleventtouchupinside];     uibarbuttonitem *backbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:backbutton];     self.navigationitem.leftbarbuttonitem = backbuttonitem; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -