0
votes

How does one change where the arrow points from as well as the position of the popover inside a tableview cell?

heres what i have so far

    else if segue.identifier == "openingHours" {
        let vc = segue.destinationViewController
        vc.preferredContentSize = CGSize(width: 200, height: 100)
        let controller = vc.popoverPresentationController
        if controller != nil {
            controller?.delegate = self
        }

    }

As you can see the popover appears in the top corner of the cell. I want the popover to appear below the blue view containing text "Arrow from below" with the arrow pointing towards the view Image

2

2 Answers

1
votes

This is a bit too late out. But if someone else stumbles upon this question:

Solution

It is based on setting the anchor for the UIPopoverController programmatically. You still need to assign it to something (for example the "view") in storyboards if you are using storyboards, but the code will override that choice.

This can be performed rather simply by applying the following to your prepare(for: sender:) and also add the desired view the UIPopoverController should anchor to in the sender parameter of performSegue(withIdentifier: , sender:)

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

    else if segue.identifier == "openingHours" {
        let vc = segue.destinationViewController

        vc.preferredContentSize = CGSize(width: 200, height: 100)
        vc?.popoverPresentationController?.delegate = self
            // Remember to pass in the cell or whatever view you want it to be anchored to in performSegue(withIdentifier: "YourSegueID", sender: tableViewCell)
            if let anchorView = sender as? UIView {
                vc?.popoverPresentationController?.sourceView = anchorView
            }
            // If you want to anchor it to a UIBarButtonItem (in a nav bar for example use this), remove the code bellow if you are using a view: 
            else if let anchorView = sender as? UIBarButtonItem {
                vc?.popoverPresentationController?.barButtonItem = anchorView
            }


     }
}
0
votes

One way is to drag from the anchor icon in the Attributes Inspector of the seque: enter image description here