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.
The
barButtonItemsare overlapped each and every time you call the method. You need to reset thebarButtonItemsby setting it asnilbefore calling the method for rearranging.It would work. Refer this link for further assistance.