Bartosz Bialecki
Bartosz Bialecki

Reputation: 4451

UISplitViewController in UITabBarController in iOS 5

I have a tabbar with splitviewcontroller on every item. I used a subclass from that site https://github.com/grgcombs/IntelligentSplitViewController and in iOS 4 every worked fine, but in iOS 5 I have a problem. When I start the app in portrait mode, then change to landscape and go to the second item in tabbar, then again change to portrait mode and click the popover, then dismiss the popover, go to the first item in tabbar, again open popover and change to the landscape, the master view disappears and popover is still visible. Has anyone any idea how to fix it?

Upvotes: 2

Views: 544

Answers (1)

Brody Robertson
Brody Robertson

Reputation: 8604

I have been working on solving the same problem. Instead of using the UISplitViewController subclass you indicate, I created a UITabBarController subclass which properly propagates the rotation messages to all UISplitViewControllers it contains. This maintains the correct internal state of the UISplitViewControllers. However, one of the SplitViewController delegate methods is not called if the SplitViewController is not visible, so I handle this in the detail view controller. I've confirmed this works in iOS5.0 - iOS6.1

OSTabBarController.m

#import "OSTabBarController.h"

@implementation OSTabBarController

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    for(UIViewController *targetController in self.viewControllers){
        if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]]){
            [targetController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
        }
    }
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    for(UIViewController *targetController in self.viewControllers){
        if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]]){
            [targetController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
        }
    }
}

@end

DetailViewController

@implementation OSDetailViewController

-(void)viewWillAppear:(BOOL)animated{
    //the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: may not have been called
    if(!UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
        self.navigationItem.leftBarButtonItem = nil;
    }
}

#pragma mark - UISplitViewControllerDelegate Methods

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];

}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
}

@end

Upvotes: 1

Related Questions