Search code examples
swiftfullscreenviewcontrolleruisplitviewcontrollermaster-detail

show a ViewController from a Detail View Controller in a UISplitViewController


My aim is: To show a popUpViewController in my project in which the user can add a "lesson" (adding a tableViewCell to a tableView) and then save it. So when the user presses a button inside the DetailViewController of a UISplitViewController , the popUpViewController should show. I also want the pop-up to be shown as fullscreen with just a small window in the middle and the rest should be black with 0.5 alpha, transparent.

My problem is: I can't find out how I have to show the popUp.


What I've tried and my results:

Tried: Showing it with present(Viewcontroller, animated:, completion: )

Result: It shows fullscreen but the other VC isnt visible in the background anymore.

Tried: The following snippet:

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popUpVC") as! PopUpViewController

self.addChildViewController(popOverVC)
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParentViewController: self)

Result: The view isnt fullscreen but only the size of the detail View Controller (doesnt cover the part of the masterViewController on the left.

Thanks for your help.


Solution

  • You might try again with present(Viewcontroller, animated:, completion: ) and using modalPresentationStyle with formSheet eg:

    let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popUpVC") as! PopUpViewController
    popOverVC.modalPresentationStyle = .formSheet
    self.present(popOverVC, animated: true, completion: nil)