-2

How can I call a method from a different class? Say I have a view controller that displays a string with its own class called ViewController1. I also have another class called ViewController2.

I want ViewController2 to be able to update the string from ViewController1 with a string value from ViewController2

How can I do this? I have looked at singleton and delegation patterns but they dont see to achieve what I am trying to do. I want regularly update a class with a string from a different class? Any help would be appreciated

1 Answers1

1

Depends on how tightly coupled you want the two classes. Should ViewController1 need to know about ViewController2 and vice versa? Are they both instances of the same class? Are they both in existence and visible at the same time? This could be as simple as VC1 calling a method on VC2, or a delegate (as you mentioned). You can look into NSNotificationCenter or KVO for more loosely coupled code.

dmorrow
  • 5,152
  • 5
  • 20
  • 31