In the iphone app that I’m working on I use a custom class to manage network communication with the host. The class called protocolClass is an ivar in the appDelegate and alloc + init in the applicationDidFinishLaunching: method.
Now whenever the protocolClass receive data from the host, it calls protocolClassDidReceiveData: method in its delegate (which I set as the appDelegate). I need then to update the data in one of the customViewControllers in the UINavigatorController.
Should I just add a reference to the customViewController I need to update in the appDelegate? or is there some other more efficient method?
If I were to keep a reference to the customViewcontroller, what are the memory usage ramifications?
Thanks in advance.
If I get you right, you want to update a view after an event occurs in some unrelated part of your program.
To reduce the number of dependencies in your code, I’d recommend to use an NSNotification instead of the more tightly coupled instance variable. Notifications are a Cocoa concept, which allows one part of your code to emit an event-like message that any number of listeners can register for.
In your case it would look like this:
AppDelegate header:
AppDelegate implementation:
in the implementation of some interested listener class (e.g. your UIViewController):