2017-03-01 79 views
0

我提出我的viewController像這樣使用accessoryButtonTappedForRowWith斯威夫特3傳遞變量PopupViewController

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) 

的彈出工程和看起來很好它只是說我提出需求到tableViewCell的標籤的viewController。我能夠獲得變量,但我不確定如何將變量傳遞給popover,因爲不會調用segue,我不認爲我能夠使用prepare(for segue: UIStoryboardSegue, sender: Any?)

+0

在navigationController呈現。 –

+1

可能的重複[傳遞變量之間沒有Segues的故事板 - Swift](http://stackoverflow.com/questions/32051629/passing-variables-between-storyboards-without-segues-swift) – Tj3n

+0

我可能不明白你是什麼說,但我不希望viewController成爲堆棧的一部分,或讓視圖導航到任何地方。 – Torewin

回答

0

這是太簡單了:

popoverContent.variableName = passingVariable 
0

您需要嵌入的viewController,您可能需要投你popOvercontent給你具體的viewController

(popoverContent as? MyViewController).myVar = value