Consider the following common situation:
You have some MainView
in your Cocoa application, loaded from a NIB, which is controlled by a MainViewController
. Your MainView
contains some controls, such as a UILabel infoLabel
. You also have a delegate MyDelegate
class which receives some sort of event.
You would like to make sure that when MyDelegate
receives its event, the infoLabel
is updated appropriately. However, the problem is that MyDelegate
does not have a reference to the MainView
or the MainViewController
and does not know about the label.
One solution is to pass a MainViewController
reference to the delegate object, but this feels wrong because you might find yourself in the undesirable situation where the object has each other's references.
What is the proper design to solve this problem?