Search code examples
objective-cmacoscocoaosx-mountain-lion

Open my Own Mac App Preferences


I am newbie in Cocoa Application.
I want to programmatically open my application's preferences window

By googling, I can just found --> [[NSWorkspace sharedWorkspace] openFile:@"MyApp.prefPane"];"

Any help would be appreciated.---

Thanks.


Solution

  • You open the preference window just like any other within your app:

    In App Delegate class:

    - (IBAction)showPreferencePanel:(id)sender {
        if (!_preferenceController)
            _preferenceController = [[PreferenceController alloc] init];
    
        [_preferenceController showWindow:self];
    }
    

    Where PreferenceController is:

    @interface PreferenceController : NSWindowController <NSWindowDelegate, NSToolbarDelegate, FontChooserViewDelegate>
    ...
    @end
    

    And in MainMenu.xib the showPreferencePanel method is hooked in like this:

    enter image description here