简体   繁体   English

拆分视图控制器不作为根视图控制器

[英]Split View Controller not as a Root View Controller

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. 用户登录后,我想使用Split View Controller来显示数据。 The trick is, that Apple doesn't want me to push the SplitViewController , since they want it to be the Root View Controller. 诀窍是,Apple不希望我推送SplitViewController ,因为他们希望它成为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? 有人知道除了创建我自己的SplitViewController类的VC 之外的任何解决方法吗?

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) 假设您正在使用故事板,并为拆分视图控制器提供了一个标识符(SplitView)

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 eg 您始终可以添加虚拟viewController并在dummyView Controller上推送splitView控制器,然后将DummyView控制器推送到当前视图控制器之上,例如

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): 这对我有帮助(通过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. 在我的应用程序的第一个屏幕上按“登录”按钮后执行Segue执行。

Also you must set split controller identifier ID (Storyboard ID) in identity inspector in storyboard (for me it is ReportSplitViewController) 您还必须在故事板中的身份检查器中设置拆分控制器标识符ID(故事板ID)(对我而言,它是ReportSplitViewController)

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. 或者,您可以在分割视图控制器的顶部以模态方式显示登录屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM