ios - Issues with UINavigationItem changing properties at runtime -
i have navigation bar, wich contains navigation item, contains 2 bar buttons, these created in storyboard, , wanted change 1 of buttons @ runtime, works:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. uinavigationitem *thisnavbar = [self mynavigationitem]; thisnavbar.rightbarbuttonitem = nil; // works, gets removed uibarbuttonitem *insertbtn = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemedit target:self action:@selector(insertskemaitem:)]; thisnavbar.rightbarbuttonitem = insertbtn; // works, sets btn }
now, in other method, called controller, not work
- (void)callchildchange { ... // remove old btn uinavigationitem *thisnavbar = [self skemanavigationitem]; thisnavbar.rightbarbuttonitem = nil; // not work? }
there nothing wrong method, runs fine, nav btn item not removed ?
skemanavigationitem navigation item, declared in .h file links navigation item made via storyboard.
your ui items need added code (by ctrl-dragging) in header file (.h) can publicly accessed other classes/view controllers.
presuming you've done this, hiding ui item best done using
relevantclass.yourviewobject.hidden = yes;
or if need delete good,
[relevantclass.yourviewobject.view removefromsuperview];
edits
options changing target method:
declare @property (nonatomic, assign) bool mybuttonwaspressed;
and:
- (ibaction) mybuttonpressed { if (!self.mybuttonwaspressed) { // code run first time button pressed self.mybutton.text = @"new button text"; self.mybuttonwaspressed = yes; } else { // code run after first time button pressed // can set bool property back, , make toggleable } }
or
- (ibaction) mybuttonwaspressedfirsttime { // need when button pressed then... self.mybutton.text = @"new button text"; [self.mybutton removetarget:self action:@selector(mybuttonpressedfirsttime) forcontrolevents:uicontroleventtouchupinside]; [self.mybutton addtarget:self action:@selector(mybuttonpressedagain) forcontrolevents: uicontroleventtouchupinside]; } - (ibaction) mybuttonwaspressedagain { // code run subsequent times button pressed }
Comments
Post a Comment