Type Method

alertControllerWithTitle:message:preferredStyle:

Creates and returns a view controller for displaying an alert to the user.

Declaration

+ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;

Parameters

title

The title of the alert. Use this string to get the user’s attention and communicate the reason for the alert.

message

Descriptive text that provides additional details about the reason for the alert.

preferredStyle

The style to use when presenting the alert controller. Use this parameter to configure the alert controller as an action sheet or as a modal alert.

Return Value

An initialized alert controller object.

Discussion

After creating the alert controller, configure any actions that you want the user to be able to perform by calling the addAction: method one or more times. When specifying a preferred style of UIAlertControllerStyleAlert, you may also configure one or more text fields to display in addition to the actions.