Re: NSAlert - Default Cancel also respond to Escape?
Re: NSAlert - Default Cancel also respond to Escape?
- Subject: Re: NSAlert - Default Cancel also respond to Escape?
- From: Andy Lee <email@hidden>
- Date: Tue, 20 May 2014 10:54:13 -0400
On May 19, 2014, at 4:30 PM, Seth Willits <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden