问题
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 !
回答1:
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;
回答2:
Instead of presenting splitviewcontroller try to set as rootviewcontroller.
self.view.window.rootViewController = splitViewController;
回答3:
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.
回答4:
Worst case scenario you could create a second UIViewController to make the push, and on it a container that have the UISplitViewController as root.
回答5:
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 (i.e 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.
来源:https://stackoverflow.com/questions/20285402/ios-how-to-segue-from-single-view-to-split-view-controller