• 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: Document object talking to main application object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Document object talking to main application object


  • Subject: Re: Document object talking to main application object
  • From: Pandaa <email@hidden>
  • Date: Sat, 31 Jul 2004 15:15:20 +0200

2004-07-31 kl. 00.02 skrev Aaron Braunstein:

OK... I've tried a couple of different ways of getting this working
and neither of them is giving me any joy, so I thought I'd run it by
the (far more experienced) denizens of this list. It's a simple thing
really, but there's some kind of conceptual block on my end preventing
things from working properly. Any help working towards a solution
would be much appreciated.
The basic setup is this: I've got a preference controller object which
manages a preference window and holds the application defaults. This
preference object is spawned during the init: of a general application
controller instance associated with the main menu nib. I have need for
an NSDocument in the application be able to query the preference object
so that it can set/reset defaults as necessary.

Unless there are special needs, you would typically use the NSUserDefaults to store, set and get preference settings. In this way, a document will in most cases have no need to talk to your preference controller.

So my problem seems to be: "How does the document object know how to
get in touch with the preference object?" I've tried two main methods,
neither of which work. The first - likely arising from a stubborn
clinging to old (i.e. pre-Cocoa) methods was to set up an extern
containing the pointer to the preference object. The second was to set
up an IBOutlet in my document class to point to the File's Owner object
of the preference's nib object.
As close to success as I can come is that the document is able to call
into the preference object... but unfortunately it's the wrong instance
(imagine my surprise when I discovered that there was more than one!)
I only ever instantiate one - via the standard [[PreferenceController
alloc] init] scheme in the application controller and nowhere else...

You mention having a PreferenceController object in your nib file. If that is so, that PreferenceController instance will be allocated and inited as a part of loading the nib. If you also explicitly [[ alloc] init] a PreferenceController somewhere that explains why you are seeing multiple instances.

What else should I consider in order to achieve my goal of having
document instances be able to reach back and talk to the preference
object? Thanks...

Since your PreferenceController is a singelton class, the usual solution would be to have a +sharedPreferenceController class method in the PreferenceController class.

Typically something like this:

static PreferenceController *sharedPrefControllerInstance;

+ (void)sharedPreferenceController
{
if ( sharedPrefControllerInstance == nil )
sharedPrefControllerInstance = [[PreferenceController alloc] init];
return sharedPrefControllerInstance;
}

- (id)init
{ // enforce singelton pattern
if ( sharedPrefControllerInstance != nil )
{
[self release];
return sharedPrefControllerInstance;
}
if ( self = [super init] )
{
sharedPrefControllerInstance = self;
}
return self;
}
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. email@hidden . . www.synapticpulse.net .
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Document object talking to main application object (From: Aaron Braunstein <email@hidden>)

  • Prev by Date: Re: Tiger feedback email address?
  • Next by Date: Re: replace authorization window
  • Previous by thread: Document object talking to main application object
  • Next by thread: Re: Document object talking to main application object
  • Index(es):
    • Date
    • Thread