G’day all,
I have been reading about protocols and delegates for passing data between controllers.
Suppose ViewControllerA creates an instance on an object:
myObject = [[anObject alloc]init];
[myObject setProperty: value];
How does ViewControllerB access myObject’s property? How does ViewControllerB become aware of objects created by ViewControllerA?
Thanks,
You can use
NSNotificationCenterto let who ever interested to know about the new object.Usually this is done in the model layer, for example I have a
Personobject.Define a “new person created notification” in the
Person.h filein the .m file
When a person is created (in the init method) post the notification
Then whoever wants to know about new persons created will need to observe this notifications , for example ViewControllerA wants to know, so in it’s init method I do: