views:

39

answers:

1

Hi,

I have an NSWindowController and I initialize it like this;

+ (MyWindowController *) sharedController
{
    static MyWindowController *singleton = nil;

    if (!singleton) singleton = [[self alloc] initWithWindowNibName: @"myWindow"];
    return singleton;
}

and I show windows like this;

[[MyWindowController sharedController] showWindow: nil];

Now the problem is that I need information from some controls on that window. But I do not want to load the window if it's not yet loaded because then I can just go with the defaults. Should I use isWindowLoaded? @property to access the singleton? or what is recommended here? (If @property, then please give me the readonly, nonatomic attributes too.)

A: 

Don't store model data in views. Have the controller (probably not MyWindowController, but the one that needs the data) own the real data (if any) and fill in any defaults.

Any values you fill in in Interface Builder should be for nothing more than sizing.

For example, if I know a field must hold a number whose value is ±50000, I'll enter “-50000” and size the field accordingly, and leave the “-50000” there. The actual default is more likely to be 0 or something, and I will have that provided by the controller that owns the value (or, if the field shows a property of a model object, I'll have the default provided by each new model object).

Peter Hosey
Thank you. By information of some controls, I actually meant something like the state of a checkbox (Just to make sure).. I don't quite understand what you're trying to say to me. Should I have an object in IB with the interface elements connected to that object instead of the NSWindowController?
Jim