Search code examples
objective-ccocoamodel-view-controllercontrollernstabview

How to handle cocoa communication between multiple controller classes


i'm new to Cocoa, maybe these questions are very basic. Currently I'm developing a mac application that uses an NSTabView, where you can switch between "app", "options" and "statistics".

Now my approach is to create three controller classes, an AppControler, an OptionsController and a StatisticsController. I created objects for them in the .xib file and linked the corresponding UI elements to the correct controller objects.

My questions are: - Is that the right way, having multiple controller objects for an NSTabView? - When I want the AppController to get information about the options, how can I do communication between App- and OptionsController?

Thanks!


Solution

  • I struggled with these types of questions a lot when I started Cocoa development. I eventually found that there's no real answer. In Cocoa and Objective-C there are so many ways to skin a cat that in the end it really ends up being up to you.

    Since all of your controllers are going to get loaded with the Nib, the easiest way to do it is to create an outlet in each controller for the other controller objects with which it wishes to communicate. Hookup the outlets in interface builder and you are set to go.

    This is an easy and effective solution in my mind. You are going to end up with circular references between the controllers but Objective-C's Nib loading/unloading code is going to take care of all of that for you.