Accessing shared (global) data object from nib
Accessing shared (global) data object from nib
- Subject: Accessing shared (global) data object from nib
- From: Andrew White <email@hidden>
- Date: Wed, 17 Nov 2004 09:27:57 +1100
I have an instance of a data object (call it CommonData) that contains
information on dynamically defined pop-up menu items. There is only 1
instance per application.
I have a nib, which contains a window with a pop-up menu.
How can I allow the WindowController (or other related class) of the nib to
locate the data object and use it to populate the pop-up menu.
So far, I have thought of the following alternatives:
* Add a category to NSApplication to obtain CommonData instance.
Problem: CommonData needs to be stored / remembered somewhere by
NSApplication, and I can't add a data member in a category.
* Subclass NSApplication, otherwise as above.
Problem: Seems very clunky way of doing it.
* In my AppController class, which creates the WindowController using
[ [MyWindowController] alloc]
initWithWindowNibName: @"MyWindowNib"
];
add another call to install the CommonData object.
Problem: I must manually trigger populating the pop-up menu after the
window is created, but before it is displayed. This seems odd. I'd like
it to 'just work'.
* Add a method to the CommonData class to allow a single instance to be
globally obtained.
Problem: Doesn't seem to be any way to create class variables (as opposed
to instance variables or class methods).
Is there a preferred solution?
--
Andrew White
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden