Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal disappearing after rotating UISplitViewController

I have a strange problem UISplitViewController. I have a button in my master view controller which opens a modal view when tapped (using a simple storyboard segue).

But the modal view disappears when I rotate the iPad, but only when rotating from portrait to landscape. My master view controller is hidden in portrait, like in the native Mail application.

If I'm in landscape (when the master is always visible) and open my modal, rotating the device works correctly and my modal stays on screen.

I tried manually triggering the segue programmatically, if I call performSegueWithIdentifier: on the splitViewController, rotating works both ways. But I was wondering if this was fixable in a simpler way because I have other buttons displaying modals in the master view controller and I don't want to do an IB action for each one and lose the advantages of storyboard segues.

like image 957
Alexandre Blin Avatar asked Nov 04 '22 01:11

Alexandre Blin


1 Answers

unfortunately it is like that, when your ipad is on portrait mode, you have a popover of your master, it is not the master in another shape. What means that you are presenting a modal using this popover as presentingViewController, so when you move from portrait to landscape the method splitViewController:willShowViewController will make your popover nil as you can see:

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // Called when the view is shown again in the split view, invalidating the button and popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.masterPopoverController = nil;
}

So I understand that is acceptable that your modal is going with it. So, with this you understand why when you put your action an call the performSegueWithIdentifier: on your splitViewController it doesn't happen, your modal is no longer connected with your popover.

So you may ask why it doesn't happen when you move from landscape to portrait.. and the reason is splitViewController:willHideViewController, it hides the viewController it doesn't remove it, so your modal is always connected.

So, unfortunately there is no solution and you will have to perform the actions by code..

I hope it helps,

Roberto

like image 97
Roberto Ferraz Avatar answered Nov 15 '22 10:11

Roberto Ferraz