0
votes

I have discovered a situation that causes dismissViewController:animated:completion to not dismiss the view controller that has been presented. While it does dismiss on iPad running iOS 8, it doesn't dismiss on iPad running iOS 7.1. I've tried self, self.presentingViewController, and self.presentedViewController - all do nothing. I've tried it with Xcode 6.0 and 6.1 beta. While I do believe this is a bug, what can be done to work around it and force dismiss that view controller, ensuring it will work for iPad running iOS 7 and 8 (presented as a popover), and iPhone running iOS 7 and 8 (presented full screen)?

I have created a very simple project you may use to try this: Xcode project zip.

Project setup:

  • Universal storyboard targeted to iOS 7+
  • Implement Popover Presentation segue
  • Implement ability to dismiss popover inside that popover

To encounter the unexpected behavior:

  1. Open the provided Xcode project
  2. Run the app on iPad iOS 7 Simulator
  3. Tap the top cell to present the popover
  4. Tap the cell in the popover to dismiss it
1

1 Answers

0
votes

The problem is in the way you try to handle the popover. To close the popover you should use the dismissPopoverAnimated method instead of dismissViewControllerAnimated.

I think you will have to make more work to complete your task for targeting both iOS versions. The root view controller should have some property to store the created popover with PoppedUpTVC as popover content and the PoppedUpTVC has to ask the root view controller to perform dismissPopoverAnimated method on the stored popover to close it.

To get a reference to the popover, try this in prepareForSegue:

if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) {
    UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
    yourDestViewController.propertyToStorePopover = popoverSegue.popoverController;
}