Aaron Bratcher
Aaron Bratcher

Reputation: 6451

iOS 5 UISplitViewController on iPad doesn't show MasterView on Portrait (but only initially)

I have a UITabBarController app where one of the tabs shows the app settings. This is a UISplitViewController with multiple detail controllers that are changed out depending on what is selected on master. My detailViewControllers have these lines which allows the master view to continually show (or should):

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.splitViewController.delegate = self;
}

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

Here's my problem: If the pad is portrait as the settings tab is tapped, only the initial detail view is shown. Not the master. Rotating the pad to landscape and back, the master shows just fine and stays there.

I can't figure out why this is happening. The XCode 4.5.2 master/detail template project doesn't have this problem after I updated the detailController to not hide the master.

Any ideas?

Upvotes: 3

Views: 1862

Answers (4)

Anand Suthar
Anand Suthar

Reputation: 3808

I know it's too late but I want to show how I escape from this So other can take benefit.

- (IBAction)hideMaster
{
   // 1. set desired width for master view
   [self.splitViewController setValue:[NSNumber numberWithFloat:0.0] forKey:@"_masterColumnWidth"];

   // 2. splitViewController delegate to self
   self.splitViewController.delegate = self;

  // 3. give a smooth animation

  [UIView animateWithDuration:1.0 animations:^{
      [self.splitViewController.view layoutSubviews];
  }];
}

- (BOOL)splitViewController: (UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation  __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
{
    return NO;
}

Upvotes: 0

Michael Navarro
Michael Navarro

Reputation: 1

The simple fix I found for this issue was to ensure that the AppDelegate had the orientation delegate:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

Upvotes: 0

Aaron Bratcher
Aaron Bratcher

Reputation: 6451

To fix the problem, I had to do the same code I used in the original question, but put it into a subclassed UISplitViewController. Originally I was putting it into the detail view.

Upvotes: 1

karlbecker_com
karlbecker_com

Reputation: 959

I just had this same problem, but figured it out by double-checking that my UISplitViewController delegate was set at the appropriate time.

Notice what's done in the XCode sample project's AppDelegate where this works correctly:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;
    }
    return YES;
}

It is specifically setting the UISplitViewController delegate to a specific view controller.

For my purposes, I set the AppDelegate to be the SplitViewControllerDelegate, since I have some slightly-complex viewcontroller management going in within the SplitViewController.

So be sure the delegate is getting set properly within application:didFinishLaunchingWithOptions: and you should have no trouble.

Upvotes: 3

Related Questions