Rizwan Shaikh
Rizwan Shaikh

Reputation: 2904

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?

Upvotes: 1

Views: 982

Answers (4)

turingtested
turingtested

Reputation: 7154

For me the problem was the .none parameter in this delegate method. When I added UIModalPresentationStyle in front of it - it started to work!

// Override the iPhone behavior that presents a popover as fullscreen
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.none
}

The reason was that I had another .none case defined in an enum in my project with another underlying Int value (which is of course bad practice, so please avoid that to begin with).

Upvotes: 0

aBilal17
aBilal17

Reputation: 3152

you can use this control else.

https://github.com/50pixels/FPPopover/

Upvotes: 0

ZeMoon
ZeMoon

Reputation: 20284

A UIPopoverController is meant for use only on iPad devices. You can refer to the Apple docs to verify.

If you really want a popover on iPhone, you can use a third-party control like WYPopoverController.

Upvotes: 0

Marcus Adams
Marcus Adams

Reputation: 53870

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..

Upvotes: 1

Related Questions