Split View Controller not as a Root View Controller

▼魔方 西西 提交于 2019-12-04 10:53:39

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.

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)

GhostCode

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];

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!