ios - Toggle visibility of UIBarButton -
i have created application has view, tableview , text view, have setup application in way when user click on button log in view takes them tableview , clicking on cell in table view takes them textview. have used single xib these. works fine. when navigate table view uibarbutton has 3 button, view(left), table view(right) , clear button(right) , when click on cell in table view goes text view , 3 button still there. require when tableview appears button log should hidden , other 2 should visible , when on textview, main , log should visible , clear button should hidden. there way achieve this?? these codes uibarbuttons:
uibarbuttonitem *clearhistory=[[uibarbuttonitem alloc]initwithtitle:@"clear history" style:uibarbuttonitemstylebordered target:self action:@selector(cleartable)]; uibarbuttonitem *btnback=[[uibarbuttonitem alloc]initwithtitle:@"back" style:uibarbuttonitemstylebordered target:self action:@selector(goback)]; self.navigationitem.leftbarbuttonitem=btnback; uibarbuttonitem *btnbacklog=[[uibarbuttonitem alloc]initwithtitle:@"back log" style:uibarbuttonitemstylebordered target:self action:@selector(gobacklog)]; self.navigationitem.rightbarbuttonitems=[nsarray arraywithobjects:clearhistory,btnbacklog, nil]; - (void)goback { self.tablelogview.hidden = yes; self.navigationcontroller.navigationbarhidden=yes; self.viewlogtoolbar.hidden=no; self.extendedview.hidden = yes; } - (void)gobacklog { self.tablelogview.hidden = no; self.navigationcontroller.navigationbarhidden=no; self.viewlogtoolbar.hidden=yes; self.extendedview.hidden = yes; } -(void)cleartable { if([tabledata count]) { uialertview *message= [[uialertview alloc] initwithtitle:@"delete history" message:@"are sure?" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"delete", nil]; [message show]; } else { uialertview *message= [[uialertview alloc] initwithtitle:@"message" message:@"no history" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [message show]; } }
modify code this: doesn't hide achieves exact same function. hope u expecting.
self.navigationcontroller.navigationbarhidden=yes; uibarbuttonitem *clearhistory=[[uibarbuttonitem alloc]initwithtitle:@"clear" style:uibarbuttonitemstylebordered target:self action:@selector(cleartable)]; self.navigationitem.rightbarbuttonitem=clearhistory; uibarbuttonitem *btnback=[[uibarbuttonitem alloc]initwithtitle:@"back" style:uibarbuttonitemstylebordered target:self action:@selector(goback)]; self.navigationitem.leftbarbuttonitem=btnback; - (void)goback { self.tablelogview.hidden = yes; self.navigationcontroller.navigationbarhidden=yes; self.viewlogtoolbar.hidden=no; self.extendedview.hidden = yes; } - (void)gobacklog { self.tablelogview.hidden = no; self.navigationcontroller.navigationbarhidden=no; self.viewlogtoolbar.hidden=yes; self.extendedview.hidden = yes; [self.navigationitem.rightbarbuttonitem settitle:@"clear" ]; [self.navigationitem.rightbarbuttonitem setaction:@selector(cleartable)]; } put code inside function u navigate tableview textview
[self.navigationitem.rightbarbuttonitem settitle:@"back log" ]; [self.navigationitem.rightbarbuttonitem setaction:@selector(gobacklog)]; if still want keep 2 right buttons in array thing u can toggle enable option between 2 buttons like
uibarbuttonitem *ubi= [self.navigationitem.rightbarbuttonitems objectatindex:0]; ubi.enabled=no/yes;
Comments
Post a Comment