0

I have 2 ViewControllers and depending on the button I press on my FirstViewController I would like to display a text on the SecondViewController.

On the FirstViewController.swift I have this:

var labelsText = String()

@IBAction func Button1(_ sender: UIButton) {
     labelsText = "test1"
     }

@IBAction func Button2(_ sender: UIButton) {
     labelsText = "test2"
     }

On the SecondViewController.swift I have this:

@IBOutlet var Label: UILabel!

override func viewDidLoad() {
        super.viewDidLoad()
        Label.text = FirstViewController.labelsText
       

I always get this error message:

Instance member 'labelsText' cannot be used on type 'FirstViewController'; did you mean to use a value of this type instead?

mt0000
  • 57
  • 5
  • how do you push or present the second viewController? – Andres Gomez Sep 26 '20 at 17:59
  • There's no surprise here, so what's the question. You can't say `FirstViewController.labelsText`. `labelsText` is a property of an _actual instance_ of FirstViewController. In any case, it is not the second view controller's job to reach back into the first view controller; the first view controller should communicate the information to the second view controller. – matt Sep 26 '20 at 17:59
  • When you are pushing it or presenting it send the data with it. The error is well justified here. – Rob Sep 26 '20 at 18:01

0 Answers0