Kevin Muldoon wrote:

I have an NSTable which receives its dataSource from MyTableController.m. However, my AppController.m needs the data MyTableController.m holds. Since AppController.m hasn't explicitly instantiated MyTableController (MyTableController being an NSObject within IB with appropriate delegates and such) how does AppController.m access MyTableController.m data? Thanks for the help.


How many MyTableController instances will there be at once?

If it's one, then you can use a Singleton pattern rooted in AppController. Simply make AppController own and manage the data source object (i.e. the Model for the table's View). AppController is already a singleton (presumably), so giving it the responsibility for other application-wide singletons isn't crazy. MyTableController then calls on the single AppController instance to obtain the data source object.

If there are multiple MyTableController instances at once, then you can have them register themselves with the single AppController when they are opened, and also unregister when closed. AppController maintains a collection of these, and depending on which table data source it wants, uses some mechanism to identify the corresponding MyTableController. An example mechanism might be sequence number (1, 2, 3), name, etc. stored as keys in a dictionary, where the value is the MyTableController instance.

You can use the register/unregister approach if there's a single MyTableController, too, but it's more complex, and there's no need when a perfectly good Singleton relationship will work.

  -- GG


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to