Search code examples
cocoanswindownswindowcontrollernspanel

Initializing Controls in NSPanel


I've got an NSPanel in my app that I use as a data export feature.

How do I initialize the controls in the panel when it's initially displayed? (i.e. using NSDefaults). There doesn't seem to be an event that fires when the window/panel opens where I can restore the default settings (basically just restoring the value of an NSPopupButton).

Currently, I'm opening the panel using '[NSApp beginSheet...]' in my App Delegate class. Should I be using an NSWindowController subclass instead?


Solution

  • Don't subclass the NSWindowController, simply subclass the NSPannel itself.

    ExportPanel.h

    #import <Cocoa/Cocoa.h>
    
    @interface ExportPanel : NSPanel {
    
    }
    
    @end
    

    ExportPanel.m

    #import "ExportPanel.h"
    
    @implementation ExportPanel
    
    - (void)awakeFromNib
    {
        // Initialize here
    }
    
    @end