Alert views display an informative alert message to the user. Alert views interrupts the user and requires them to stop what they’re doing to choose an action or dismiss the alert. In this tutorial we will display an alert view when the user clicks a button.
Open Xcode and create a new Single View Application. For product name, use iOS7AlertViewTutorial and then fill out the Organization Name, Company Identifier and Class Prefix fields with your customary values. Make sure only iPhone is selected in Devices.
Go to the Storyboard and drag a button to the main view. Give the button a title of "Show Alert".
Select the Assistant Editor and open ViewController.m. Ctrl and drag from the button to the @interface section and create the following Action
Implement the showAlert method
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert View Tutorial" message:@"Button is clicked." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
Build an Run this project, select the button and an alert view will be displayed.
You can download the source code of the iOS7AlertViewTutorial at the ioscreator repository on github.