Luke_i Luke_i - 23 days ago 9
Swift Question

Show Label Value on 2nd View - Swift

Since i'm new and a newbie on Swift can someone tell me how I can get the label value on screen 1 to show on screen 2. Thanks

enter image description here

Edit: So I tried the way you told me but for some reason the Label text did not change in View 2. Any help? Thanks

enter image description here

enter image description here

Joe Joe
Answer

I am passing textFiled data to destViewController to show how segue performs when passing data.

Note: If you want to pass string data to your destVC.You can assign your string like var someValue: : String

mainStoryBoard:

enter image description here

MainVC:

  @IBOutlet weak var textField: UITextField! 
  //or you can assign string like var someValue: : String

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let viewController = segue.destination as! destVC
        viewController.dataText = textField.text // someValue.text
  }

DestVC:

@IBOutlet var label: UILabel!

var dataText = String()
override func viewDidLoad()      
label.text = dataText                 
}

Output:

enter image description here