Search code examples
iosuiviewcontrolleruisplitviewcontroller

Loading UIViewController from UISplitViewController


I have a UISplitViewController from which I need to load a UIViewController. I know I can do this as a modal, but that's not what I'm after. I need for the UIViewController to load like a normal VC occupying the full screen and when the DONE button is touched for it to return to the UISplitViewController. Thus far, when I've tried to do this it loads into one half of the UISplitViewController instead of replacing it.

So, my question is, "Is this even possible?" and if so, how? Currently I'm using the modal (PageSheet), which would be fine in Portrait orientation but just looks bad in Landscape.

Currently, my Split View is set up in the App Delegate via a tab bar as follows:

AdminMasterViewController *adminMasterVC = [[AdminMasterViewController alloc] init];
adminMasterNav.viewControllers = [NSArray arrayWithObjects:adminMasterVC, nil];

AdminDetailViewController *adminDetailVC = [[AdminDetailViewController alloc] init];
adminDetailNav.viewControllers = [NSArray arrayWithObjects:adminDetailVC, nil];

UISplitViewController *adminSplitVC = [[UISplitViewController alloc] init];
adminSplitVC.viewControllers = [NSArray arrayWithObjects: adminMasterNav, adminDetailNav, nil];
adminSplitVC.delegate = self;
adminSplitVC.title = @"Admin";

Then loaded with the tab bar.

I don't know why I just can't grasp the relationships of VCs to one another, apparently a missing chunk of brain matter.


Solution

  • why you don't want to use modal? you can have a full screen, just set up modal presentation style

    YourUIViewController *viewController = (YourUIViewController*)[yourStoryboard instantiateViewControllerWithIdentifier:@"YourUIViewController"];
    [viewController setModalPresentationStyle:UIModalPresentationFullScreen];
    
    /*some additional logic if needed*/   
    
    [yourSplitViewController presentViewController:viewController animated:NO completion:nil];