• 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: Customize NSAlert?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customize NSAlert?


  • Subject: Re: Customize NSAlert?
  • From: Ron Fleckner <email@hidden>
  • Date: Sun, 22 Apr 2007 15:04:45 +1000

Hi,

Just wanted to add my two cents to this old thread. I was looking to do something similar (ie, add a "Don't show this again" checkbox to an alert panel/sheet), but I wanted to have it work on 10.2, so NSAlert can't be used.

I've come up with a very simple, if crude, solution using NSBeginAlertSheet() which is "Available in Mac OS X v10.0 and later."

1. Get the button ready before running the alert. alloc/ initWithFrame(something like (10,10,200,18) for a checkbox with title) and set it's title (@"Don't show this again"), type (NSSwitchButton) and etc. (Don't need an action because we just want it's state.)

2. Run the alert, setting the button pointer as the contextInfo parameter, then...

3. NSView *view = [[NSApp keyWindow] contentView];
[view addSubview:mySwitchButton];
[mySwitchButton release];
This adds the button AFTER the sheet opens, but it's very quick. With NSBeginAlertSheet() there's plenty of room on the panel at the bottom left for the button so it doesn't interfere with what's already there.


4. In the didEnd: method for the sheet...
   NSButton *button = contextInfo;
   BOOL aBool = [button state];
   ... and now you've got it.

Works a treat. I'm anticipating that the user will only want to see this particular alert once, so aesthetics aren't a high priority, though it doesn't actually look bad.

Like I said, this is just my two cents worth. If anybody can see a reason why I shouldn't do this, I'd really like to know.

Ron
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Customize NSAlert?
      • From: "Finlay Dobbie" <email@hidden>
  • Prev by Date: Re: Cocoa-dev Digest, Vol 4, Issue 390
  • Next by Date: Re: subclass of NSManagedObject not behaving as expected
  • Previous by thread: Re: Cocoa-dev Digest, Vol 4, Issue 390
  • Next by thread: Re: Customize NSAlert?
  • Index(es):
    • Date
    • Thread