ios - rightBarButtonItem seems to stack when moving from one viewController to another -


my problem have created rightbarbuttonitem each view in storyboard, rightbarbuttonitem in app supposed keep track of total cost of items user has added shopping list. in viewdidload on first viewcontroller set rightbarbuttonitem's customview uilabel. when moving viewcontroller set viewcontroller's rightbarbuttonitem 1 previous viewcontroller. however, when move previous viewcontroller viewcontroller's rightbarbuttonitem doesn't change when try update it. instead, looks did when moved previous time, if move same viewcontroller again first viewcontroller's rightbarbuttonitem seems 1 step behind should upon return. in other words, viewcontroller's rightbarbuttonitem seems stack when moving viewcontroller.

any appreciated.

-- relevant code:

viewdidload - first viewcontroller

double total;  - (void)viewdidload{     total = 0;     nsstring *text = [nsstring stringwithformat:@"$%.2f", total];     uifont *cellfont = [uifont fontwithname:@"helvetica" size:17.0];     cgsize constraintsize = cgsizemake(maxfloat, maxfloat);     cgsize labelsize = [text sizewithfont:cellfont constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping];     uilabel *customitem = [[uilabel alloc] initwithframe:cgrectmake(0, 0, labelsize.width, labelsize.height)];     [customitem settext:text];     [customitem setfont:[uifont fontwithname:@"helvetica" size:15.0]];     [self.navigationitem.rightbarbuttonitem setcustomview:customitem]; } 

prepareforsegue - first viewcontroller

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{     orderviewcontroller *orderviewcontroller = (orderviewcontroller *)segue.destinationviewcontroller;     [orderviewcontroller.navigationitem.rightbarbuttonitem setcustomview:_rightbarbuttonitem.customview]; } 

viewwilldisappear - second viewcontroller

- (void)viewwilldisappear:(bool)animated{     [super viewwilldisappear:animated]; // sendtotalbackfromorder delegate method upon returning first viewcontroller     [_delegate sendtotalbackfromorder:_total];     [self removefromparentviewcontroller]; } 

sendtotalbackfromorder - firstviewcontroller

// method becomes apparent rightbarbuttonitem being stacked , 'behind' should - (void)sendtotalbackfromorder:(double)currtotal{     total = currtotal;     nsstring *text = [nsstring stringwithformat:@"$%.2f", total];     uifont *cellfont = [uifont fontwithname:@"helvetica" size:17.0];     cgsize constraintsize = cgsizemake(maxfloat, maxfloat);     cgsize labelsize = [text sizewithfont:cellfont constrainedtosize:constraintsize linebreakmode:nslinebreakbywordwrapping];     uilabel *customitem = [[uilabel alloc] initwithframe:cgrectmake(0, 0, labelsize.width, labelsize.height)];     [customitem settext:text];     [customitem setfont:[uifont fontwithname:@"helvetica" size:15.0]];     [self.navigationitem.rightbarbuttonitem setcustomview:customitem]; } 

just change lines in viewdidload , sendtotalbackfromorder:

[self.navigationitem.rightbarbuttonitem setcustomview:customitem]; 

for

uibarbuttonitem *barbtn = [[uibarbuttonitem alloc] initwithcustomview:customitem];  self.navigationitem.rightbarbuttonitem = barbtn; 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -