View Single Post
Mark FX

 
Mark FX's Avatar
 
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 168
Mark FX has a spectacular aura about

Mark FX is offline
The NSAlert's buttons return an integer, depending on which button is clicked, so you should use an if end if condition check like this.

Code:
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Delete"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Delete the record?"];
[alert setInformativeText:@"Deleted records cannot be restored."];
[alert setAlertStyle:NSWarningAlertStyle];

if ([alert runModal] == NSAlertFirstButtonReturn) {
    // Delete button clicked.
} else {
    // Cancel button clicked.
}
Or.

Code:
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Answer this question?"];
[alert setAlertStyle:NSWarningAlertStyle];

NSInteger result = [alert runModal];

if ( result == NSAlertFirstButtonReturn ) {
        // Yes button clicked 
} else if ( result == NSAlertSecondButtonReturn ) {
        // No button clicked
} else if ( result == NSAlertThirdButtonReturn ) {
        // Cancel button clicked
}
If you use the class method.
+ (NSAlert *)alertWithMessageTextNSString *)messageTitle defaultButtonNSString *)defaultButtonTitle alternateButtonNSString *)alternateButtonTitle otherButtonNSString *)otherButtonTitle informativeTextWithFormatNSString *)informativeText
To create your alert panel.

Then you can check the NSAlertDefaultReturn = 1, NSAlertAlternateReturn = 0, NSAlertOtherReturn = -1, or NSAlertErrorReturn = -2 to check for an error, in the same way as the above examples.

Hope this helps.

Regards Mark
QUOTE Thanks