Re: Accessing shared (global) data object from nib
Re: Accessing shared (global) data object from nib
- Subject: Re: Accessing shared (global) data object from nib
- From: Joakim Danielson <email@hidden>
- Date: Wed, 17 Nov 2004 00:21:49 +0100
Why don't you make CommonData a singleton, as such it can be called
from anywhere in your application, i.e [[CommonData sharedInstance]
someMethod].
Another solution is to set a delegate for NSApplication and let that
delegate contain a CommonData object.
Joakim
On 2004-11-16, at 23.27, Andrew White wrote:
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
_______________________________________________
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