How do I get the property value from a container view in Swift

后端 未结 1 1539
囚心锁ツ
囚心锁ツ 2021-01-07 06:56

I have 1 UIViewController that contains a UIContainerView and a UIButton. Also, I have a UITableViewController (It has a UITextField and a UITextView) that is embedded in th

相关标签:
1条回答
  • 2021-01-07 07:33

    When your main view loads, the container performs a segue to its assigned initial / root ViewController. At that point, you can get a reference to it:

    var theFieldsTVC: FieldsTVC?
    

    Now, in prepare for segue, assign that variable:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
        if segue.identifier == "TVCSegue" {
    
            if let vc = segue.destination as? FieldsTVC {
                theFieldsTVC = vc
            }
    
        }
    }       
    

    Then, you can:

    @IBAction func buttonTapped(_ sender: Any) {
    
        self.textField.text = theFieldsTVC?.textField?.text
        self.textView.text = theFieldsTVC?.textView?.text
    
    }
    
    0 讨论(0)
提交回复
热议问题