ios - how to stop view disappearing when navigation controller left bar button pressed -
i rookie ios .in child view controller made modification in data. inserted done button store data , pop view controller navigation controller stack. if press navigation controller button automatically goes without saving data. if made modification in data , pressed button need show alert "modifications made sure want go back". if user press cancel button in alert view need stop view disappearing , still stand on same view controller.if have answer please me.
i think way it
- (void)viewdidload{ [super viewdidload]; [self.navigationitem setleftbarbuttonitem:nil]; [self.navigationitem sethidesbackbutton:yes]; uibutton *mybutton = [[uibutton alloc] initwithframe:cgrectmake(0, 0, 100, 44)]; [mybutton setimage:[uiimage imagenamed:@"back.png"] forstate:uicontrolstatenormal]; //back.png = image name [mybutton settitle:@"back" forstate:uicontrolstatenormal]; [mybutton settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; [mybutton addtarget:self action:@selector(backbuttontapped:) forcontrolevents:uicontroleventtouchupinside]; uibarbuttonitem *custombackbutton = [[uibarbuttonitem alloc] initwithcustomview:mybutton]; [self.navigationitem setleftbarbuttonitem:custombackbutton]; } - (void)backbuttontapped:(id)sender{ uialertview *alert = [[uialertview alloc] initwithtitle:@"message" message:@"modifications made sure want go back" delegate:self cancelbuttontitle:@"go back" otherbuttontitles:@"stay here", nil]; [alert show]; } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex{ if (buttonindex == [alertview cancelbuttonindex]){ [self.navigationcontroller popviewcontrolleranimated:yes]; }else{ //stay on page , } }
don't forget add <uialertviewdelegate>
Comments
Post a Comment