4

I have an app that requires user to LOG IN. Once user is logged in, I want to use Split View Controller to display data. The trick is, that Apple doesn't want me to push the SplitViewController, since they want it to be the Root View Controller. From my point of view, it is okay, but I need the user to log in first.

Anybody knows any workaround except creating my own SplitViewController-like VC?

Michal
  • 15,429
  • 10
  • 73
  • 104

4 Answers4

1
UISplitViewController *svc = (UISplitViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"SplitView"];
[self presentModalViewController:svc animated:YES];

Assuming you are using storyboards, and have given the split view controller an identifier (SplitView)

Brett Gregson
  • 5,867
  • 3
  • 42
  • 60
  • When I do this the app crashes: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a Split View Controllers modally' – Bocaxica Oct 28 '13 at 10:45
1

You can always add a dummy viewController and push the splitView controller on the dummyView Controller and then push the DummyView Controller on top of your present view controller e.g.

AppDelegate *appdelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
self.splitViewController.delegate = detailViewController;
UIViewController *dummyView = [[UIViewController alloc]init];
[dummyView.view addSubview:self.splitViewController.view];
[appdelegate.rootNavigationController setNavigationBarHidden:YES animated:NO];
[appdelegate.rootNavigationController pushViewController:dummyView animated:YES];
kleopatra
  • 51,061
  • 28
  • 99
  • 211
GhostCode
  • 452
  • 6
  • 17
1

This helped for me (via Xamarin):

public override bool ShouldPerformSegue (string segueIdentifier, NSObject sender)
    {
        if (segueIdentifier != ReportSettingsSegue)
            return base.ShouldPerformSegue (segueIdentifier, sender);

        bool isOk = ProcessLogin (); 
        var svc = (ReportSplitViewController)Storyboard.InstantiateViewController ("ReportSplitViewController");
        View.Window.RootViewController = svc;

        return isOk;
    }

Segue perform after pressing "log in" button on my app's first screen.

Also you must set split controller identifier ID (Storyboard ID) in identity inspector in storyboard (for me it is ReportSplitViewController)

0

You can still change the root view controller if you need to. You can initially set the root view controller to show your login screen, and then replace it with the split view controller. Alternatively, you could present your login screen modally over the top of the split view controller.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • 2
    This is a nice idea, but from iOS8 and up, presenting a new screen on top doesn't seem to be 'instant', so it'll show you the splitscreen for a moment and then the login on top, which is just plan ugly. – Kevin R Jun 10 '15 at 10:55