简体   繁体   中英

ios How To Segue From Single View To Split View Controller

I have two template Views (one is a single view and the other is a Split View Controller) each individually works fine. So I put a button on the Single View and put a Push Segue on the button to go to the Split View Controller. When I press the button I get a crash saying Push cant be used from outside UI Navigation Contoller.

Ok so I put the single view template into a UI Navigation Controller and it now says: Split View Controllers cannot be pushed to a Navigation Controller.

So ... how do I do this ??

Thanks !

而不是呈现 splitviewcontroller 尝试设置为 rootviewcontroller。

self.view.window.rootViewController = splitViewController;

Use a container view in a normal View Controller, covering up the whole viewing area, and that container view has an embed segue to the Split View Controller

Overwrite the UISplitViewController and put this in the viewDidLoad if you need to communicate between them:

YourLeftVC *masterViewController = (YourLeftVC *) [[self.viewControllers objectAtIndex:0] topViewController];
YourRightVC *detailViewController = [self.viewControllers objectAtIndex:1];

masterViewController.delegate = detailViewController;

As per apples documentation https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html

A split view controller must always be the root of any interface you create. you must always install the view from a UISplitViewController object as the root view of your application's window.

What you can do here is create a custom splitview.

最坏的情况是,您可以创建第二个 UIViewController 来进行推送,并在其上创建一个以 UISplitViewController 为根的容器。

Set your segue to modal and not push, that should do it.

EDIT

Actually that doesn't work. What you can try is putting your splitView in another storyboard, and in your buttonClicked: method present it in code :

In SigleView.m :

- (IBAction)buttonClicked:
{
    SplitViewController *splitVC = [[UIStoryboard storyboardWithName:@"SplitStoryBoard" bundle:nil] instantiateViewController];
    [self presentViewController:splitVC animated:YES completion:nil];
}

EDIT2

What's written before isn't working either. I really wonder if you CAN present a splitViewController (ie not make it your rootViewController).

But there's someting you can do :

Set your splitView as the rootView of your app, present modally your singleView at launch, and whenever you want just dismiss it to let the splitView have control. Will have the same effect than having your singleView presenting the splitView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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