reconfigureForMasterInPopover crashes when dismissing modal View Controller (Full screen mode) #16

pothibo opened this Issue Aug 16, 2010 · 7 comments


None yet
4 participants

pothibo commented Aug 16, 2010

If I dismiss my modal view controller, it crashes due to this line of code:

} else if (!inPopover && _hiddenPopoverController && _barButtonItem) {
    // I know this looks strange, but it fixes a bizarre issue with UIPopoverController leaving masterViewController's views in disarray.
    [_hiddenPopoverController presentPopoverFromRect:CGRectZero inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

It crashes with the following raised exception:
'Popovers cannot be presented from a view which does not have a window.'

in order to fix this, I added (... && self.view.window) at the following condition:
else if (!inPopover && _hiddenPopoverController && _barButtonItem && self.view.window)

I didn't test it thoroughly but it seems it has fixed my issue.

The MGSplitViewController is in a window, but I guess that the modal is presented into another UIWindow which is why it temporarly has no UIWindow property set.

this reintroduces the masterViewController's views' disarray bug, though..

pothibo commented Aug 17, 2010

really? so it happens when the view doesn't belong to the window?

If the app has a modal view controller (i.e. a login controller) which is presented at application launch, I can reproduce the bug with the following steps:

  1. Start the app in portrait
  2. When the modal controller is shown, rotate to landscape
  3. Dismiss the controller.
    With your suggested fix the app won't crash but the masterView's tableview frame won't be aligned correctly. Rotating again to portrait and then back to landscape fixes the issue

ghost commented Sep 3, 2010

I think I have a similar issue. When I present a modal view controller, in either Landscape or Portrait, everything is fine. Once I dismiss the modal view controller, the orientation in the detailViewController goes completely wonky. It is rotated 90 degrees. I can't fix it by rotating the device.

I don't get the original crash, but I tried adding the self.view.window check anyway. It didn't change anything for me.

Does anyone else see an issue like this? Am I doing something wrong? Is there a work around? (It works fine on a vanilla UISplitViewController).


ghost commented Sep 3, 2010

OK, I just found a workaround for my issue. I was using:

[self presentModalViewController:changePasswordVC animated:YES];

from my detailViewController, but I if override presentModalViewController:animated: dismissModalViewControllerAnimated: to present/dismiss the modal view controller using the MGSplitViewController as the receiver, things work properly. E.g.

 - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
    [self.splitViewController presentModalViewController:modalViewController animated:animated];

felixyz commented Oct 15, 2010

I had a crash when reusing the same MGSplitViewController and showing its view as a modal view, if the orientation had changed between the two modal view presentations. Fixed it by adding this condition immediately before the crashing line (same place that others have seen):

    if ([self.view window])
        [_hiddenPopoverController presentPopoverFromRect:CGRectZero inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

I have never seen "masterViewController's views' disarray bug" so can't say if this is reintroduced or not. But if it does one could use the view's didMoveToWindow method or (better) some method in the controller to insert the magic line there. (?)

Thanks a lot Felixyz, your code works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment