I basically have a Master-Detail style app that uses a PageViewController in the DetailViewController. The PageViewController has three different scenes. Depending on the current scene I am setting different rightBarButtonItems
in each of the three. Two of the scenes only have one rightBarButtonItem, but one of the scenes uses two.
If the user scrolls fully from one page to the next there is no issue. However if the user only scrolls part way in the direction of the rightBarButton items and lets the screen pop back, only one of the bar button items will appear.
According to the Apple documentation:
If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the left side of the bar are not displayed.
This explains what is happening. When the view loads the buttons it must perform a check of the frame size available for the buttons. The controller sees the buttons will overlap the title and therefore eliminates one. I simply need to delay when the buttons appear or something of this nature. Does anyone have any ideas on how to overcome this?
Here is how I have the buttons declared in viewDidLoad of the DetailViewController
//Generate buttons
barButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
[barButton setImage:[UIImage imageNamed:@"arrow-up.png"]];
barButton2 = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
[barButton2 setImage:[UIImage imageNamed:@"arrow-down.png"]];
The buttons are then passed into the required viewController and displayed in viewDidAppear
.
- (void) viewDidAppear:(BOOL)animated
{
//downButton and upButton are set from barButton and barButton2 which were created in the `DetailViewController`
[upButton setTarget:self];
[downButton setTarget:self];
[downButton setAction:@selector(action1)];
[upButton setAction:@selector(action2)];
navItem.rightBarButtonItems = @[downButton, upButton];
}
Here is some images to see the before and after