swiftios9popoveruipopover

Swift/iOS 9: using Popover Presentation with a UITableViewCell


I keep getting this error because I cannot correctly anchor my segue. I've tried a mixture of using Storyboards and coding.

enter image description here enter image description here

I'm a newbie to iOS, so I've been unsuccessfully trying to solve this problem by looking at this solution, as well as Youtube videos. Any help would be greatly appreciated!


Solution

  • From my experience it is easier to just do this programatically and forget about the segue / storyboard all together.

    This works in 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)
    
    }