Chapter 12. Using Alert Panels

Occasionally, you will want to warn the user about something by means of an alert panel. Alert panels are easy to create. While most things in Cocoa are object-oriented, showing an alert panel is typically done with a C function: NSRunAlertPanel(). Here is the declaration:

int NSRunAlertPanel(NSString *title, NSString *msg,
       NSString *defaultButton, NSString *alternateButton,
       NSString *otherButton, ...);

The code:

int choice = NSRunAlertPanel(@"Fido", @"Rover",
                             @"Rex", @"Spot", @"Fluffy");

would result in the alert panel shown in Figure 12.1.

Example Alert Panel

Figure 12.1. Example Alert Panel

Note that the icon on the panel will be the ...

Get COCOA PROGRAMMING FOR MAC OS X SECOND EDITION now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.