Swift 3 - Passing data between a View Controller and after that to another 2

后端 未结 2 1310
-上瘾入骨i
-上瘾入骨i 2021-01-16 03:45

I\'m trying to perform a segue which it doesn\'t work. What i\'m trying to do is send the data which i have in a textfield in my View Controller(Main), after that i want t

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 04:11

    1.So get rid of this code, because if you are calling performSegue you don’t need that one.

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "OP") as! OpcionesController
    self.present(nextViewController, animated:true, completion:nil)
    

    2.Then in the prepareForSegue

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if segue.identifier == “YourSegueIdentifier" {
        let destination: OpcionesController = segue.destination as! OpcionesController
        destination.name = txtCorreo.text
      }
    }
    

    3.Replace this code:

    if let nametoDisplay = name {
        displayLbl.text = name
    }
    

    with:

    displayLbl.text = name
    

提交回复
热议问题