Search code examples
iphoneuikitios10uipopovercontrollerpopover

popover doesn't display on iphone


I followed this UIPopoverPresentationController on iPhone doesn't produce popover but doesn't produce popover on iphone. Here is the code of viewcontroller

class ViewController:UIViewController,UIPopoverPresentationControllerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        if segue.identifier == "second"{

            let secondVC = segue.destination
            let controller : UIPopoverPresentationController = secondVC.popoverPresentationController!
            controller.delegate = self
        }
    }

    /* Popover delegate method */
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
        return UIModalPresentationStyle.none
    }
}

I am not able to show new viewcontroller using present as popover in iphone. (ios 10/xcode8)

After clicking on button secondViewController should popover on that button.


Solution

  • After using this delegate method it is producing popover on iphone.

    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    
        return UIModalPresentationStyle.none
    }