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.
[alert addButtonWithTitle:@"OK"]; [alert addButtonWithTitle:@"Cancel"]; [alert setMessageText:@"Sheet Title"]; [alert setInformativeText:@"Message text goes here."]; [alert setAlertStyle:NSWarningAlertStyle]; [alert beginSheetModalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(someMethodDidEnd:returnCode:contextInfo:) contextInfo:nil]; - (void) someMethodDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo { if(returnCode == NSAlertFirstButtonReturn) { // Do something } }
You need to login to post a comment.
