-1

i want to pass data to next view controller but i don't want to move to that view controller. i want to move to another view controller. here is my testing code Home View Controller is the class which i want to send data. and i want to move to another view controller which is moving through segue. this method give me null value to homeviewcontroller

    if email.text == em && pwd.text == pw
    {

        let des = HomeViewController()
        des.ema = em
        self.performSegue(withIdentifier: "segue", sender: nil)            
    }
  • Possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – pableiros Apr 28 '17 at 19:21

1 Answers1

0

Add on prepareforSegue method :

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "segue" {
        let destination = segue.destination as! HomeViewController
        destination.ema = em
    }
}

Or if you want an "other" View Controller

 let viewController = storyboard.instantiateViewController(withIdentifier :"HomeViewController")
 viewController.ema = em
 self.present(viewController, animated: true)
MarionFlex
  • 92
  • 4