Swift/iOS 9: 将 Popover Presentation 与 UITableViewCell 一起使用

Swift/iOS 9: using Popover Presentation with a UITableViewCell

我一直收到这个错误,因为我无法正确锚定我的 segue。我已经尝试过混合使用故事板和编码。

我是 iOS 的新手,所以我一直试图通过查看 this solution 以及 Youtube 视频来解决这个问题,但没有成功。任何帮助将不胜感激!

根据我的经验,以编程方式执行此操作并忘记 segue/storyboard 会更容易。

这适用于 swift 2.0

func showPopOverBox(button:UIButton) {
    let popoverViewController = self.storyboard?.instantiateViewControllerWithIdentifier("yourviewcontrollerstoryboardId") as UIViewController!
    popoverViewController.modalPresentationStyle = .Popover
    popoverViewController.preferredContentSize   = CGSizeMake(600, 600)

    let popoverPresentationViewController = popoverViewController.popoverPresentationController

    popoverPresentationViewController?.permittedArrowDirections = UIPopoverArrowDirection.Any
    popoverPresentationViewController?.sourceView = button
    popoverPresentationViewController?.sourceRect = button.bounds

    presentViewController(popoverViewController, animated: true, completion: nil)

}

这是 Swift 3.0 答案:

    func showPopOverBox(button:UIButton) 
    {
        let popoverViewController = self.storyboard?.instantiateViewController(withIdentifier: "yourviewcontrollerstoryboardId")   UIViewController!
        popoverViewController?.modalPresentationStyle = .popover
        popoverViewController?.preferredContentSize = CGSize.init(width: 600, height: 600)

        let popoverPresentationViewController = popoverViewController?.popoverPresentationController

        popoverPresentationViewController?.permittedArrowDirections = UIPopoverArrowDirection.up
        popoverPresentationViewController?.sourceView = button
        popoverPresentationViewController?.sourceRect = button.bounds

        present(popoverViewController!, animated: true, completion: nil)
    }