• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSAlert - Default Cancel also respond to Escape?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSAlert - Default Cancel also respond to Escape? (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: kCGStatusWindowLevel
  • Next by Date: Re: kCGStatusWindowLevel
  • Previous by thread: Re: NSAlert - Default Cancel also respond to Escape?
  • Next by thread: Quartz Display Services & Retina Display Modes
  • Index(es):
    • Date
    • Thread