New format of UIAlertView and UIActionSheet after iOS8.0, ios8.0uialertview

Source: Internet
Author: User

New format of UIAlertView and UIActionSheet after iOS8.0, ios8.0uialertview

After iOS8.0, Apple updated the creation methods of UIAlertView and UIActionSheet. In previous versions, the two alert controls have their own creation methods, but after iOS8.0, they use the UIAlertController controller class for unified creation. However, the previous creation method is not effective in Versions later than iOS8.0 and can still be used normally. Next we will record the new writing method.

First, let's look at the example of Apple API writing:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"                               message:@"This is an alert."                               preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault   handler:^(UIAlertAction * action) {}]; [self presentViewController:alert animated:YES completion:nil];

In this example, an alert is created in its class method:
alertControllerWithTitle:message:preferredStyle:
PreferredStyle defines the type of the created prompt box, which is an enumerated value. You can select different prompt box styles.

The second class in the example: UIAlertAction creates an action: the user clicks a different button to trigger different events. However, in the example, this action is not added to the prompt box. We can use:

- (void)addAction:(UIAlertAction *)action;

This method adds the behavior to the prompt box.

Below is a small demo:

/*! @ Brief after iOS8.0, the creation methods of alert and action sheet have changed: they are uniformly created by UIAlertController. The previously created alert method is still available in ios8. @ since * // create an alert UIAlertController * alert = [UIAlertController alertControllerWithTitle: @ "Attention! "Message: @" Your Device Haven't PhotoLibrary. "preferredStyle: Regular]; // define action event UIAlertAction * action = [UIAlertAction actionWithTitle: @" OK "style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * action) {NSLog (@ "callback after the OK button is clicked") ;}]; // Add the action time to the prompt box [alert addAction: action]; // The prompt box [self presentViewController: alert animated: YES completion: nil];



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.