Question

I was just wondering if when I create my App Preferences if it's better to either have all of the views in one XIB and have:

-(id)initWithSelectedToolBarItem: (NSToolBarItem*)toolBarItem{
    self = [self initWithNibName: [[toolBarItem label] stringByReplacingOccurrencesOfString:@" " withString:@""] bundle:nil];
    // init code in initWithNibName...
    if (!self) return nil;
        return self;
}

Or just go the conventional route and have separate nibs etc...?

The reason why I ask is because so far the project is getting huge (as in the number of separate files) and I'm trying to shave it down a bit.

Any advice would be really appreciated!

Cheers in advance :)

Was it helpful?

Solution

My preferences window code has each of the views, which are switched using a toolbar like yours, in a single .xib with an outlet to each NSView instance from the preference window controller:

@interface PreferenceController : NSWindowController <NSWindowDelegate, NSToolbarDelegate, FontChooserViewDelegate> {
    // Main window
    IBOutlet NSToolbar *_toolbar;
    IBOutlet NSBox *_box;
    IBOutlet NSButton *_restoreDefaultsButton;
    IBOutlet NSView *_generalPrefsView;
    IBOutlet NSView *_boardPrefsView;
    IBOutlet NSView *_movesPrefsView;

    // Other outlets to individual UI elements on some of the views.
}

So I'd say "Yes", you should do that, however there is no need to subclass the NSView and hence no need to worry about special initialisation.

EDIT Actually, that's a lie; one of the views is subclassed but uses standard NSView initialisation (initWithFrame and awakeFromNib).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top