Set tags on your buttons to distinguish them. Have them both target the same action method:
- (IBAction) buttonAction:(NSButton*)sender
{
[NSApp stopModalWithCode:[sender tag]];
[self.window close];
}
Get rid of your _dialogCode
instance variable and -windowWillClose:
method.
-[NSApplication runModalForWindow:]
will already center the window, so you can get rid of your -awakeFromNib
method.
Get rid of the invocation of -[NSWindowController loadWindow]
. That's an override point. You're not supposed to call it. The documentation is clear on that point. It will be called automatically when you request the window controller's -window
.
Get rid of the static instance of MyPasswordWindowController
. Just allocate a new one each time. There's no point in keeping the old one around and it can be troublesome to reuse windows.