2

In Xcode 6, I am building a universal app that has a UISplitViewController. On iOS 8 devices that are small, it looks like a normal master/detail relationship, but on larger devices, you see both the master and detail views at the same time.

This works well for iOS 8, but I also need it to support iOS 7. iOS 7 supports UISplitViewController only for iPads, while I currently have it used for both iPad and iPhone.

How can I get around this issue?

erdekhayser
  • 6,537
  • 2
  • 37
  • 69

3 Answers3

1

@macworth as Jack said it is possible but I'm not sure if you can do it from code. I also had a problem (getting the same "only supported when running under UIUserInterfaceIdiomPad" exception) when using a storyboard, however. After much nashing of teeth I figured out it was because I was using an old xcode imported project and did not have Use Sizes Classes checkbox enabled for the storyboard. After enabling that, xcode upgraded the project, and it worked fine.

I also had to make some tweaks to handle cases where a nav controller is used instead of a split view controller. In particular, in the default xcode split view controller project I had to make the following #if 1'd change to prepareForSeque():

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSDate *object = self.objects[indexPath.row];

#if 1
        DetailViewController *controller = nil;
        if ([segue.destinationViewController isKindOfClass:[UINavigationController class]]) {
            controller = (DetailViewController*)[segue.destinationViewController topViewController];
        }
        else if ([controller isKindOfClass:[UISplitViewController class]]) {
            controller = segue.destinationViewController;
        }
#else
        DetailViewController *controller = (DetailViewController*)[[segue destinationViewController] topViewController];
#endif
        [controller setDetailItem:object];
        controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
        controller.navigationItem.leftItemsSupplementBackButton = YES;
    }
}
mbbeme
  • 116
  • 4
0

Actually, I found that UISplitViewController works on iPhones running iOS 7 as well if you build using SDK 8 (Xcode 6); the default example project can be run with the following caveats:

  • The master and detail view controllers are directly controlled by the split view controller.

  • The array of view controllers contains a direct reference to only the master view controller; the detail view controller is not there.

  • As a direct consequence of the above, you can't show toolbars inside your master and detail view controllers, because those are controlled using navigation controllers.

  • When you don't implement any of the new split view delegate protocol methods, you may see notice the detail view controller is shown in portrait mode; this question has the answer to that issue.

Btw, from my short experiments I found that for both iOS 7 and 8 the Autolayout guides are a bit wonky in the detail view; alignments for either the top or bottom layout guide must be adjusted to -64 and -44 respectively.

Tested the above with iPhone 4S on iOS 7.1.2

Community
  • 1
  • 1
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
  • Hmm, I'm using Xcode6.1, SDK 8.1, iphone 4s simulator 7.1. Wen I do, `UISplitViewController *split = [[UISplitViewController alloc] init];` I get `UISplitViewController is only supported when running under UIUserInterfaceIdiomPad` Any suggestions? – mackworth Oct 28 '14 at 20:19
  • 1
    @mackworth I think they've only made it compatible when you use interface builder :) – Ja͢ck Oct 28 '14 at 22:06
  • Aha; that explains it. Thanks! – mackworth Oct 29 '14 at 01:15
0

I had this same problem. In your UISplitViewController delegate add reference to the older delegate method

///
/// Used by iOS 7 iPad
///
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return NO;
}

Doing that made it so that on the iOS 7 iPad it shows the master and detail at the same time like it does in iOS 8

geekydevjoe
  • 108
  • 1
  • 7