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

Customize NSAlert?


  • Subject: Customize NSAlert?
  • From: Jerry Krinock <email@hidden>
  • Date: Sun, 04 Feb 2007 07:58:48 -0800
  • Thread-topic: Customize NSAlert?

I want to add a "Don't ask this again" checkbox to an NSAlert's panel.  In
the list archives, it's proposed that you can get the NSAlert's -window and
customize as desired.

But the original poster never confirmed that it worked [1], and it doesn't
work for me.  I can get the -window, and then the window's -contentView, and
their -frames, do -setFrame to increase the height, add a button, and all
this looks happy in code, but as soon as I -runModal, the frame sizes get
set back to the original sizes and my button never shows.

Am I doing something wrong, or do I have to use the yucky old
NSGetInformationalAlertPanel and customize it instead?  (Another thread in
archives states that customizing NSGetInformationalAlertPanel has actually
been done and works. [2])

Thanks,

Jerry Krinock

References:
[1] http://www.cocoabuilder.com/archive/message/cocoa/2005/7/5/140831
[2] http://www.cocoabuilder.com/archive/message/cocoa/2004/8/8/114009

Some of my code:

NSAlert *alert = [[NSAlert alloc] init];
NSPanel* panel = [alert window] ;
NSView* contentView = [panel contentView];

// Should not be needed, but try this anyhow:
NSSize maxSize = {FLT_MAX, FLT_MAX} ;
[panel setMaxSize:maxSize] ;

// Get original sizes
NSRect wframe = [panel frame] ;
NSRect cframe = [contentView frame] ;
SSLogSizeToConsole(wframe) ;
SSLogSizeToConsole(cframe) ;

// Increase window and contentView height by 200
wframe.size.height = wframe.size.height + 200 ;
cframe.size.height = cframe.size.height + 200 ;
[panel setFrame:wframe display:NO] ;
[contentView setFrame:cframe] ;

// Log the increased frame sizes
SSLogSizeToConsole([panel frame]) ;
SSLogSizeToConsole([contentView frame]) ;
// Log shows: They're 200 higher.  Wonderful!!!

// Add a button
NSButton* dontAskButton = [[NSButton alloc] init] ;
[dontAskButton setTitle:SSLocalizedString(@"dontAskAgain", @"")] ;
[contentView addSubview:dontAskButton] ;

// Run the sucker
int reply = [alert runModal] ;

// Log the sizes again
SSLogSizeToConsole([panel frame]) ;
SSLogSizeToConsole([contentView frame]) ;
// Log shows: They're back to original heights.  ARGGHH!!!


_______________________________________________

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: Michael Babin <email@hidden>
    • Re: Customize NSAlert?
      • From: "Finlay Dobbie" <email@hidden>
    • Re: Customize NSAlert?
      • From: Nick Zitzmann <email@hidden>
    • Re: Customize NSAlert?
      • From: Sam DeVore <email@hidden>
  • Prev by Date: Re: No double click event available to an NSView?
  • Next by Date: Binding to a specific element in an array
  • Previous by thread: Re: No double click event available to an NSView?
  • Next by thread: Re: Customize NSAlert?
  • Index(es):
    • Date
    • Thread