iosswiftuipopover

Popover Doesn't Work on iPhone


I implemented a Popover in my application and tested it. It will work fine on iPad but when I test it on iPhone, instead of showing Popover it will show the full storyboard. Please help me.

Here is my code:

@IBAction func MenuIsClick(sender: AnyObject) {
    var moveToNextVC:MenuViewController

    moveToNextVC = self.storyboard?.instantiateViewControllerWithIdentifier("MenuViewController") as! MenuViewController
    moveToNextVC.modalPresentationStyle = .Popover
    moveToNextVC.preferredContentSize = CGSizeMake(200, 200)

    if let popoverController = moveToNextVC.popoverPresentationController {
        popoverController.sourceView = sender as! UIView
        popoverController.sourceRect = CGRect(x: 0, y: 0, width: 85, height: 30)
        popoverController.permittedArrowDirections = .Any
        popoverController.delegate = self

    }
    presentViewController(moveToNextVC, animated: true, completion: nil)

}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle {
    return .None
}

Edit: As Popover is not work on iPhone but when a refer this EthanStrider/iOS-Projects it will work fine. How?


Solution

  • UIPopoverController's are only available on iPad.

    Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.

    Though with iOS 8+, it no longer crashes, it will be executed as full screen modal presentation..