Search code examples
ipaduisplitviewcontroller

App organization and UISplitViewController


I have a problem with my app organization. I want an home view with four buttons. Each one pushing the view to a splitView.

So in my home view, I do not want any masterView displayed, ether in portrait or landscape mode. But in my four next views, I want the masterView displayed at any time and I want to be able to have a back button to return to the home view.

My question is how do I achieve such a thing ?

  • Do I have to create my home View as the rootViewController of the app and then create one splitView per button. Then create a back button to dismiss the splitView.
  • Do I have to create one single splitView and play around with the master view display. I can't figure out how to hide my master class in portrait mode on certain views and show it on other views.

Solution

  • A UISplitViewController has to be the root view controller.

    So you would start your app with a homeViewController that contains four buttons, each of which would tell your app delegate to remove the home view controller from root and create a splitViewController and make that the root.

    Obviously to go back you would need a button on your splitViewController that would tell the app delegate to remove the splitViewController and replace with the newly loaded homeViewController.


    an example of getting a viewController from a storyboard and attaching it to the window

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *homeViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
    [window addSubview:homeViewController.view];
    [window makeKeyAndVisible];