prepareForSegue and PerformSegueWithIdentifier sender

后端 未结 6 926
执笔经年
执笔经年 2021-02-03 13:18

I am wondering about how the functions in the title work and also about the sender parameter.

Lets say a button click calls the performSegue method, does that also call

6条回答
  •  遇见更好的自我
    2021-02-03 14:03

    The_Curry_Man's answer worked for me. Here's an update of his code for Swift 3.

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    
        performSegue(withIdentifier: "test", sender: self)
        //You can set the identifier in the storyboard, by clicking on the segue
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "test"{
            var vc = segue.destinationViewController as! RandomViewController
            vc.data = "Data you want to pass"
            //Data has to be a variable name in your RandomViewController
        }
    }
    

提交回复
热议问题