Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to dismiss a modal presentation of UISplitController in Portrait orientation

my project is in swift 2 and works in both orientation.

i have a UISplitViewController presented modally.

in the navigation bar of master view i have a bar button for dismiss this.

when i open the controller in landscape mode the close button work well because master view is always visibile and his parent and presenting view controller are ok.

the problem is in the portrait orientation because master view isn't always visible and his parent and presenting controller are null when i tap the cancel button.

there is a solution?

thanks in advance

presenting controller

i present a modal splitViewController from storyboard:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "splitSegue" {

    let split = segue.destinationViewController as! UISplitViewController
    let masterNav = split.viewControllers[0] as! UINavigationController
    let master = masterNav.topViewController as! MasterController
    master.delegate = self
}}

and this is the delegate fun for dismiss:

func updateAppCategory(master: MasterController) {

    self.presentedViewController?.dismissViewControllerAnimated(true, completion: nil)
}
like image 765
giorgio83 Avatar asked Dec 22 '25 13:12

giorgio83


1 Answers

I had have the same issue and found a solution:

splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible

When you insert this in viewdidload, then you can dismiss the splitviewcontroller in portrait and landscape mode

like image 132
Edgar Leifeld Avatar answered Dec 24 '25 05:12

Edgar Leifeld



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!