We Recommend

Programming in Objective-C Programming in Objective-C
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming. The book makes no assumption about prior experience with object-oriented programming languages or with the C language (upon which Objective-C is based). And because of this, both novice and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C.


Posted By

tylerhall on 08/14/07


Tagged

cocoa alert nsalert sheet


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

MrYAMANE
strangesthings
snowdrop


Run an NSAlert Sheet in your Cocoa App


Published in: Objective C 


This code runs an alert sheet in your Cocoa app. You first create an NSAlert object, its properties, and define the method that should be called when the user dismisses the sheet. Then write the corresponding handler that tests for an "OK" or "Cancel" button press.


  1. NSAlert *alert = [[[NSAlert alloc] init] autorelease];
  2. [alert addButtonWithTitle:@"OK"];
  3. [alert addButtonWithTitle:@"Cancel"];
  4. [alert setMessageText:@"Sheet Title"];
  5. [alert setInformativeText:@"Message text goes here."];
  6. [alert setAlertStyle:NSWarningAlertStyle];
  7. [alert beginSheetModalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(someMethodDidEnd:returnCode:contextInfo:) contextInfo:nil];
  8.  
  9. - (void) someMethodDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
  10. {
  11. if(returnCode == NSAlertFirstButtonReturn)
  12. {
  13. // Do something
  14. }
  15. }

Report this snippet 

You need to login to post a comment.