0

I am presenting my viewController like so using accessoryButtonTappedForRowWith:

let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let popoverContent = storyboard.instantiateViewController(withIdentifier: "Test")

        popoverContent.modalPresentationStyle = .popover

        if let popover = popoverContent.popoverPresentationController {
            let viewForSource = self.createCharacterView as UIView
            popover.sourceView = viewForSource

            // the position of the popover where it's showed
            popover.sourceRect = viewForSource.bounds

            // the size you want to display
            popoverContent.preferredContentSize = CGSize(width: 200,height: 200)
            popover.delegate = self
        }

        self.present(popoverContent, animated: true, completion: nil)

The pop up works and looks fine it's just that the viewController that I am presenting needs to the label of the tableViewCell. I am able to get the variable, but I'm unsure how to pass the variable to the popover since a segue isn't called I don't think I am able to use prepare(for segue: UIStoryboardSegue, sender: Any?).

Torewin
  • 887
  • 8
  • 22
  • You need to embed the viewController to be presented in the navigationController. – Sachin Vas Mar 01 '17 at 03:56
  • 1
    Possible duplicate of [Passing variables between Storyboards without Segues - Swift](http://stackoverflow.com/questions/32051629/passing-variables-between-storyboards-without-segues-swift) – Tj3n Mar 01 '17 at 03:59
  • I may not understand what you're saying, but I do not want the viewController to be part of the stack or have the view navigate anywhere. – Torewin Mar 01 '17 at 03:59
  • Thanks @Tj3n that helped fix the problem! – Torewin Mar 01 '17 at 04:08

2 Answers2

0

It was too simple:

popoverContent.variableName = passingVariable
Torewin
  • 887
  • 8
  • 22
0

You might need to cast you popOvercontent to you specific viewController

(popoverContent as? MyViewController).myVar = value
Abel C
  • 62
  • 4