Last active
January 20, 2021 04:08
-
-
Save marteinn/540cfa4282add987ee6b to your computer and use it in GitHub Desktop.
NSAlert Example: How to show a NSAlert as a sheet in a NSView (Cocoa)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSAlert *alert = [[NSAlert alloc] init]; | |
[alert setMessageText:@"Delete this project?"]; | |
[alert setInformativeText:@"Deleted projects cannot be restored"]; | |
[alert addButtonWithTitle:@"OK"]; | |
[alert addButtonWithTitle:@"Cancel"]; | |
[alert setAlertStyle:NSWarningAlertStyle]; | |
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) { | |
if (returnCode == NSAlertSecondButtonReturn) { | |
NSLog(@"Delete was cancelled!"); | |
return; | |
} | |
NSLog(@"This project was deleted!"); | |
}]; |
@sn0wyfall Nope, this is Objective-C.
It appears that NSWarningAlertStyle has been deprecated
NSAlertStyle enum now has NSAlertStyleCritical, NSAlertStyleInformational, and NSAlertStyleWarning
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@marteinn is this for Swift 3? It looks like it's for Swift 2