Search code examples
iosswiftuipopovercontroller

Popover works in iOS 8 but not iOS 7


When running my app in iOS 7 I get the following error when trying to display a popover: [UIPopoverController dealloc] reached while popover is still visible

It works fine in iOS 8.

My code to show the popup is:

let vc = InfoViewController()
vc.setText(txt)
vc.modalPresentationStyle = .Popover
var w=vc.width
if w<200 {
   w=200
}
vc.preferredContentSize = CGSizeMake(w+30,height+30)
let popRect = rect
let aPopover =  UIPopoverController(contentViewController: vc)
aPopover.presentPopoverFromRect(popRect, inView: view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)

Solution

  • An easy way to fix this is declare your popover as a member variable of your class and using it.

    var aPopover : UIPopoverController?
    

    And in that method change the code like:

    self.aPopover =  UIPopoverController(contentViewController: vc)
    self.aPopover!.presentPopoverFromRect(popRect, inView: view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)