• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing shared (global) data object from nib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Accessing shared (global) data object from nib
      • From: Andrew White <email@hidden>
References: 
 >Accessing shared (global) data object from nib (From: Andrew White <email@hidden>)

  • Prev by Date: the image not the icon
  • Next by Date: Re: How to embed a popup menu in an NSTextField
  • Previous by thread: Accessing shared (global) data object from nib
  • Next by thread: Re: Accessing shared (global) data object from nib
  • Index(es):
    • Date
    • Thread