Question

I'm implementing a master detail application on iOS 7, the master view controller is a navigation controller which can navigate through two table view controllers. The detail is a simple view controller that displays an image.

I have implemented UISplitViewController methods in the detail:

- (BOOL) splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return UIInterfaceOrientationIsPortrait(orientation);
}

- (void) splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
    UINavigationController* nav= (UINavigationController*)aViewController;
    barButtonItem.title= nav.topViewController.title;
    self.navigationItem.leftBarButtonItem= barButtonItem;
}

- (void) splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    self.navigationItem.leftBarButtonItem= nil;
}

The problem is that splitViewController:willHideViewController:withBarButtonItem:forPopoverController: is not called when the user dismisses the master view controller with a gesture.

This cases the problem that if the user navigates through the master's navigation controller and then dismisses the master, the tab bar button item shows the old title.

To make it clearer I'll explain what happens step by step. The master's navigation controller's root navigation controller's title is "Top Places". The pushed view controller's title is "Photos". When the app starts there's no master in portrait mode:

enter image description here

The the user presents the "Top Places" view controller:

enter image description here

Then the user navigates to the second view controller: "Photos":

enter image description here

Then the user dismisses the master, but the tab bar button item still keeps it's old title "Top Places":

enter image description here

The problem is that the split view controller delegate doesn't have a method called when the master is dismissed via a gesture.

Was it helpful?

Solution

There is no UISplitViewControllerDelegate delegate method at all for detecting when the popover is dismissed while in portrait orientation. It doesn't matter how it is dismissed. If you wish to know, setup a delegate for the popover controller.

The splitViewController:willHideViewController:withBarButtonItem:forPopoverController: delegate method is called when you rotate from landscape to portrait.

OTHER TIPS

You don't need to know when the master view is dismissed, just set the title of the button according to the navigation item title of the current topViewController of the navigation controller. You can do this by making your detail controller the delegate of the navigation controller,

@interface DetailController ()
@property (strong,nonatomic) NSString *barButtonTitle;
@end

@implementation DetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [(UINavigationController *)self.splitViewController.viewControllers[0] setDelegate:self];
    self.splitViewController.delegate = self;
    self.navigationItem.leftBarButtonItem.title = [[(UINavigationController *)self.splitViewController.viewControllers[0] topViewController] navigationItem].title;
}


- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    self.barButtonTitle = viewController.navigationItem.title;
    self.navigationItem.leftBarButtonItem.title = self.barButtonTitle;
}



- (BOOL) splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
    return UIInterfaceOrientationIsPortrait(orientation);
}



- (void) splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
    barButtonItem.title= self.barButtonTitle;
    self.navigationItem.leftBarButtonItem= barButtonItem;
}



- (void) splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    self.navigationItem.leftBarButtonItem= nil;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top