0

Trying to add and remove navigation Bar Items on the navigation bar, some bar items disappear.

When I run the codes below at viewDidLoad, they work fine.

-(void) resetNavigationBarRearrangeMode {

    NSArray*rightBarItems = [[NSArray alloc] initWithObjects:actionCancel, actionSave, actionAddItem, actionRearrange, nil];

    self.navBar.topItem.rightBarButtonItems = rightBarItems;

}

When I try to remove some of the bar button items, it appears fine.

- (IBAction)cancelClicked:(id)sender {



    NSArray*rightBarItems = [[NSArray alloc] initWithObjects:actionRearrange, nil];


    self.navBar.topItem.rightBarButtonItems = rightBarItems;

    Log(@"running cancel");
}

But when I clicked rearrange to run the below code, this doesn't work.

- (IBAction)rearrangeClicked:(id)sender {


        [self resetNavigationBarRearrangeMode];


}

Anyone know what's wrong? thanks in advance.

tipsywacky
  • 3,374
  • 5
  • 43
  • 75

1 Answers1

1

The barButtonItems are overlapped each and every time you call the method. You need to reset the barButtonItems by setting it as nil before calling the method for rearranging.

 - (IBAction)rearrangeClicked:(id)sender {

    self.navigationItem.rightBarButtonItem = nil;
    [self resetNavigationBarRearrangeMode];


    }

It would work. Refer this link for further assistance.

Community
  • 1
  • 1
iOS
  • 3,526
  • 3
  • 37
  • 82
  • i tried self.navigationItem.rightBarButtonItem = nil;.. Do you mean to put self.navBar.topItem.rightBarButtonItems = nil; both ways doesn't work. – tipsywacky Aug 24 '12 at 06:21