Looks like UIBarButtonItems don't have a property one can use to hide them. So, in order to hide such button I need to remove it from the toolbar. I have two methods that remove a rightmost button from a toolbar and put it back. The toolbar has two buttons and a flexible space between them.
The toolbar and everything else in the view is created in IB, the toolbar (bottomToolBar property) is an IBOutlet, but the button (restartButton property) isn't. I am setting it manualy in the code.
This is what I have now:
Is there a better way to do it?
The toolbar and everything else in the view is created in IB, the toolbar (bottomToolBar property) is an IBOutlet, but the button (restartButton property) isn't. I am setting it manualy in the code.
This is what I have now:
Code:
- (void)hideRestartBarButton
{
NSUInteger itemsInToolBar = [self.bottomToolBar.items count];
if (itemsInToolBar == 3) {
NSMutableArray *tmpItems = [self.bottomToolBar.items mutableCopy];
self.restartButton = [tmpItems objectAtIndex:2];
[tmpItems removeObjectAtIndex:2];
self.bottomToolBar.items = tmpItems;
[tmpItems release];
}
}
- (void)showRestartBarButton
{
NSUInteger itemsInToolBar = [self.bottomToolBar.items count];
if (self.restartButton && (itemsInToolBar == 2)) {
NSMutableArray *tmpItems = [self.bottomToolBar.items mutableCopy];
[tmpItems addObject:self.restartButton];
self.bottomToolBar.items = tmpItems;
[tmpItems release];
}
}
Is there a better way to do it?