I have an application that uses a UISplitViewController
. I am adding it's delegate and assigning a button on the navigation bar for when the app is in portrait mode, to be able to show the master view controller in a popover view :
/*
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
*/
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// do smth
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
#pragma mark - UISplitViewDelegate methods
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"", @"");
UIImage *imag = [[UIImage imageNamed:@"gray_button"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 7, 0, 7)];
UIImage *imag_pressed = [[UIImage imageNamed:@"gray_button_pressed"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 7, 0, 7)];
UIImage *more = [UIImage imageNamed:@"shows_button_pressed.png"];
[barButtonItem setBackgroundImage:imag forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barButtonItem setBackgroundImage:imag_pressed forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[barButtonItem setImage:more];
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
If an option is chosen in the master view controller, the RootViewController( which is basically the detail split of my split view controller ) will change with a replace-type segue. Once again I am assigning the UISplitViewController
delegate.
My issue is, the bar button doesn't show after the root has been changed unless I put the device in landscape mode and then go back to portrait. If I do so, the button is there and does it's job.
How could I make the button appear without putting the device on landscape and then going back to portrait?
PS: I've tried both assigning the new delegate in prepareForSegue:
method in the old root view controller and assigning the new delegate in viewWillAppear:
method in the new root view controller. The same thing happens.
Another thing : the new root view controller implements the <UISplitViewControllerDelegate>
UPDATE :
I found that the method : - (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
gets called only after I go from landscape to portrait so that is why I need to rotate the device in order to get the button to show.
The difference between the two delegates is that the first one is added in my AppDelegate.m
and the second one in the prepareForSegue:
method, in the old root view controller. The above method gets called for the old root view controller as soon as the app launches.