1.1. Displaying Alerts with UIAlertView
Problem
You want to display a message to your users in the form of an alert. This could be used to ask them to confirm an action, to ask for their username and password, or simply to let them enter some simple text that you can use in your app.
Solution
Utilize the UIAlertView
class.
Discussion
If you are an iOS user, you have most certainly already seen an alert view. Figure 1-1 depicts an example.

Figure 1-1. Example of an alert view in iOS
The best way to initialize an alert view is to use its designated initializer:
-(void)viewDidAppear:(BOOL)paramAnimated{[superviewDidAppear:paramAnimated];UIAlertView*alertView=[[UIAlertViewalloc]initWithTitle:@"Alert"message:@"You've been delivered an alert"delegate:nilcancelButtonTitle:@"Cancel"otherButtonTitles:@"Ok",nil];[alertViewshow];}
When this alert view is displayed to the user, she will see something similar to that shown in Figure 1-2.

Figure 1-2. A simple alert view displayed to the user
In order to display an alert view to the user, we use the
alert view’s show method. Let’s have
a look at the description for each of the parameters that we passed to
the initializer of the alert view:
titleThe string that the alert view will display on the top when it is shown to the user. This string is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access