On May 19, 2014, at 4:30 PM, Seth Willits <sli...@araelium.com> wrote: > Any ideas on how to get a Cancel button which is both the default button and > responds to escape? Both require setting the button's key equivalent and > there can only be one.
This seems to work: NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:@"Message text"]; [alert setInformativeText:@"Informative text."]; NSButton *okButton = [alert addButtonWithTitle:@"OK"]; NSButton *cancelButton = [alert addButtonWithTitle:@"Cancel"]; [cancelButton setFrame:NSMakeRect(10000, 10000, 0, 0)]; [cancelButton setTarget:okButton]; [cancelButton setAction:@selector(performClick:)]; [alert runModal]; It uses the fact that > any button with a title of “Cancel” has a key equivalent of Escape You don't need to set the target and action, but they complete the illusion of Esc being a key equivalent for the OK button. --Andy _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com