ios - generic / central popViewControllerAnimated method -
i have sweet little question , scenario:
question: can have [self.navigationcontroller popviewcontrolleranimated:true]
being controlled central class insted of having repeated in every view.
so have far: view:
//this want accomplish , repeat in every view. want pass on own navigationcontroller , have central class add action (and style) leftbarbutton [self.navigationitem setleftbarbuttonitem:[actionscollection setgenericbackbutton:self.navigationcontroller]]; central class:
@interface actionscollection () @property(nonatomic, weak)uinavigationcontroller *navctrl; // since dont seem able pass self.navigationcontroller on buttons action selector (se bellow). @end setgenericbackbutton does:
-(uibarbuttonitem *)setgenericbackbutton:(uinavigationcontroller *)navcontrl{ _navctrl = navcontrl; // can global (to class) uinavigationcontroller being reached -(ibaction)backbuttonaction (see bellow) uibutton* mybackbutton = [buttonmaker btntypeback]; //just returns styled btn //this starts fail - want pass 'navcontrl' on selector bunt havnt figured out how (thats why global variable '_navcontrl' [mybackbutton addtarget:self action:@selector(backbuttonaction) forcontrolevents:uicontroleventtouchupinside]; uibarbuttonitem* backbtnitem = [[uibarbuttonitem alloc]initwithcustomview:mybackbutton]; } backbuttonaction does:
-(ibaction)backbuttonaction{ [_navctrl popviewcontrolleranimated:true]; } am lazy trying save lines of code trying impossible or can done? more happy explain better.
good programmers lazy.
that said, if set uinavigationcontroller add own buttons , you. shouldn't need code beyond [self.navigationcontroller pushviewcontroller:someviewcontroller animated:yes];
Comments
Post a Comment