Suppression Button (Cocoa)

Do you want to know more about it? Ok then, again is quite simple!

Allocate and initialize your NSAlert somewhere in your code.

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Information"]!=YES){
 
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
 
[alert addButtonWithTitle:@"OK"];
 
[alert setMessageText:@"Information"];
 
[alert setInformativeText:@"blah blah."];
 
[alert setShowsSuppressionButton:YES];
 
[alert beginSheetModalForWindow:main modalDelegate:self didEndSelector:@selector(infoDidEnd:returnCode:contextInfo:) contextInfo:nil];
 
}

Use a selector and check the state of the suppression button!

-(void) infoDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo{
if(returnCode == NSAlertFirstButtonReturn){
if ([[alert suppressionButton] state] == NSOnState) 
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"Information"];
}
}
Wednesday, July 1, 2009   ()