0

I have two files that are of importance. I have a file which is the ViewController and a file named 'Registration'

Inside of the view controller I have a label that is linked from the view. Inside of Registration I have a function that needs to change the text in view.

But when referncing label1.text inside the function it it says that it is an unresolved identifier, so it's not seeing the label.

How would I be able to reference a label in a function in another file that is identified in the view controller?

Alex Catchpole
  • 7,156
  • 6
  • 20
  • 29
  • You need a reference to your view controller object, however you should review your design as the classes should be decoupled. You could use a delegation pattern or NSNotificationCenter, for example, to advertise the change in data and have the view controller update the field appropriately – Paulw11 Sep 28 '14 at 13:46

1 Answers1

0

Here is a Stack Overflow discussion on NSNotification in swift:

NSNotificationCenter addObserver in Swift

Another to to work on this depends if I understand your setup.

ViewController1 has the label. ViewController 2 has the function that may modify what goes in the label

For this case then you segue between views and pass the data via prepareForSegue You can use a protocol/delegate to move the entered data in View 1 back to ViewController2.

ViewController 1 has a the label Model1 has the function (I recommend this way if possible)

The you directly call the function from within ViewController 1

Community
  • 1
  • 1
Steve Rosenberg
  • 19,348
  • 7
  • 46
  • 53