Reputation: 3464
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.
Upvotes: 0
Views: 1346
Reputation: 3626
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.
Upvotes: 1