Search code examples
iosobjective-cmaster-detail

Bring in .xib only in detail view in master view design


I've looked at a few examples but I haven't been able to get things to work properly yet. I am in a large code base that is a universal app. I am bringing in a .xib like so:

TestView *newView =
[[TestView alloc] init];

[self presentViewController:newView animated:YES completion:nil];

That loads the .xib just fine on the iPhone side of things, but in the iPad sim the .xib covers the whole screen. How can I make it to only cover the details view? I understand that in the appdelegate it makes two view controllers (i.e. the splitviewcontroller) but I have no option to do something like

[detailViewController presentViewController:newView animated:YES completion:nil];

Solution

  • You have to create an instance of a UISplitViewController in the AppDelegate. The UISplitViewController is only availabe on the iPad, so you have to enclose this in an if-statement

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UIViewController *master = [self buildMaster];
        UIViewController *detail = [self buildDetail];
        UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
        splitViewController.viewControllers = @[master, detail];
        [self.window setRootViewController:splitViewController];
    }