Basic use of UIAlertController, uialertcontroller
After ios8, the system's pop-up box, UIAlertView and UIActionSheet, starts at the same time and uses a new Controller called UIAlertControllerUIAlertController. The basic usage of creating UIAlertControllerTitle: displayed title message: description information displayed at the bottom of the title: preferredStyle: the bullet box style is divided into two types: timeline. Two styles are displayed as follows: Step 1: Create the Controller UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @ "are you sure you want to exit? "Message: @" displayed information "preferredStyle: UIAlertControllerStyleActionSheet]; Step 2: Create a UIAlertActionUIAlertAction for each button in the create button dialog box as follows: actionWithTitle: the text style to be displayed by the button: The style to be displayed by the button is divided into three types: UIAlertActionStyleDefault: Default style, the default button color is blue UIAlertActionStyleCancel: Set the button to cancel. click "cancel" to exit the dialog box. note: Only one cancellation style can be set. If multiple cancellation styles exist, an error will occur. UIAlertActionStyleDestructive: dangerous operation button. The color of the button is red male handler. When you click the button, the internal code of the Block is called. UIAlertAction * action = [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * _ Nonnull action) {NSLog (@ "click Cancel");}]; UIAlertAction * action1 = [UIAlertAction actionWithTitle: @ "OK" style: UIAlertActionStyleDestructive handler: ^ (UIAlertAction * _ Nonnull action) {NSLog (@ "click Cancel"); [self. navigationController popViewControllerAnimated: YES];}]; Step 3: add the created UIAlertAction to the Controller. [alertController addAction: action]; [alertController addAction: action1]; in addition to the Add button, you can also add a text box, provided that the style of UIAlertController must be in the UIAlertControllerStyleAlert style. otherwise, an error will be reported directly to add the text box as follows: [alertController addTextFieldWithConfigurationHandler: ^ (UITextField * _ Nonnull textField) {textField. placeholder = @ "text box point text" ;}]; running effect: Get the added text box through the textFields attribute of the controller. note that textFields is an array. UITextField * textF = alertController. textFields. lastObject; Step 4: display the pop-up box. (equivalent to the show operation) [self presentViewController: alertController animated: YES completion: nil];