uinavigationbar - Objective C UIBarButtonItem as toggle button for edit and save -


i have written code place right bar button item customview.while selecting edit changes save option.now selecting save saves values.if again try select edit action not firing.the code written below,

item = [[uinavigationitem alloc]init];     btnn = [uibutton buttonwithtype:uibuttontypecustom]; [btnn setframe:cgrectmake(0, 0, 40, 40)]; btnn.layer.maskstobounds = no; btnn.layer.cornerradius = 8.0; [btnn addtarget:self action:@selector(rightbarbuttoncustompressed:) forcontrolevents:uicontroleventtouchupinside]; [btnn setimage:[uiimage imagenamed:@"edit"] forstate:uicontrolstatenormal]; uibarbuttonitem* rightbtn = [[uibarbuttonitem alloc] initwithcustomview:btnn];    item.rightbarbuttonitem = rightbtn; self.navigationbar.items = @[item]; 

-(ibaction)rightbarbuttoncustompressed:(uibarbuttonitem*)btn {

item = [[uinavigationitem alloc]init]; btnn = [uibutton buttonwithtype:uibuttontypesystem]; [btnn setframe:cgrectmake(0, 0, 40, 40)]; btnn.layer.maskstobounds = no; btnn.layer.cornerradius = 8.0; [btnn addtarget:self action:@selector(savebtnclicked:) forcontrolevents:uicontroleventtouchupinside]; [btnn settitle:@"save" forstate:uicontrolstatenormal]; uibarbuttonitem* rightbtn = [[uibarbuttonitem alloc] initwithcustomview:btnn]; item.rightbarbuttonitem = rightbtn;        self.navigationbar.items = @[item];  [self.firstnametext setenabled:yes]; [self.lastnametext setenabled:yes]; [self.dateofbirthtxt setenabled:yes]; [self.contactnumberlbl setenabled:yes]; 

}

-(ibaction)savebtnclicked:(uibarbuttonitem*)btn {

[self.firstnametext setenabled:no]; [self.lastnametext setenabled:no]; [self.dateofbirthtxt setenabled:no]; [self.contactnumberlbl setenabled:no]; item = [[uinavigationitem alloc]init]; btnn = [uibutton buttonwithtype:uibuttontypecustom]; [btnn setframe:cgrectmake(0, 0, 40, 40)]; btnn.layer.maskstobounds = no; btnn.layer.cornerradius = 8.0; [btnn addtarget:self action:@selector(rightbarbuttoncustompressed:) forcontrolevents:uicontroleventtouchupinside]; [btnn setimage:[uiimage imagenamed:@"edit"] forstate:uicontrolstatenormal]; uibarbuttonitem* rightbtn = [[uibarbuttonitem alloc] initwithcustomview:btnn]; item.rightbarbuttonitem = rightbtn;    self.navigationbar.items = @[item]; 

i need achieve barbuttonitem toggle save , edit option.please me fix this.thanks

in place of alloc init evry time , why don't try changing buttontitle , can perform action on basis of


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -