O'Reilly logo

Cocoa Programming for Mac OS X, Third Edition by Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. 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. Most things in Cocoa are object oriented, but showing a modal 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 15.1.

Example Alert Panel

Figure 15.1. Example Alert Panel

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required