Basic use of UIAlertController, uialertcontroller

Source: Internet
Author: User

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];

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.