0

I need to modally present a UISplitViewController (both on iPhone and on iPad) and it should have a transparent background (I will add the blur view). I was able to do it when presenting a UIViewController, but it doesn't work with the split view controller. My split view controller has 2 navigation controllers.

My result is that the master view controller has black background.

Thanks for the help.

Oded
  • 795
  • 2
  • 12
  • 32

1 Answers1

1

Is your UISplitViewController the root view controller? It can exhibit strange behavior if not. Per Apple:

Note

"...Although it is possible to install a split view controller as a child in some other container view controllers, doing is not recommended in most cases. Split view controllers are normally installed at the root of your app’s window. ..."

I've used this (called from Detail view controller, using the Split View Controller with two nav controllers.) At this point I wanted to reset the nav stacks:

let firstVC = self.storyboard?.instantiateViewController(withIdentifier: "FirstViewController") as! FirstViewController
let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
    // Get a reference the the Master View nav controller
let masterNav = self.splitViewController!.viewControllers[0] as! UINavigationController
    // Set desired VC's as nav stack RootViewControllers        
self.navigationController?.setViewControllers([matchVC], animated: true)
masterNav.setViewControllers([masterMatchTableView], animated: true)

You could call .pushViewController on both Navigation Controllers instead, if you want to maintain the nav stack.

If you're still working on this, post some code and I'd be happy to take a look at it.

edit:

So, you can't modally present a Split View Controller: https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html

A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application’s window. The panes of your split view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface. Split view controllers cannot be presented modally.

The code snippet I posted above will present both Master and Detail Views at the same time. Or, you could present a new VC as the Detail View, and set the UISplitViewController.preferredDisplayMode = .primaryHidden to modally present a single VC.

  • Is there a way to present the SplitViewController (either modally or by push) with transparent background? I need the master VC and the detail VC to be transparent. – Oded Oct 19 '16 at 11:35