The new wording of Uialertview and Uiactionsheet after iOS8.0

Source: Internet
Author: User

After iOS8.0, Apple updated the creation method for Uialertview and Uiactionsheet. In previous versions, the two controls that reminded the user had their own method of creation, but after iOS8.0, the controller class was created uniformly using Uialertcontroller. However, the previous method of creation did not work in the version after iOS8.0, and it still works. A new notation is recorded below.

First look at an example of the Apple API:

uialertcontroller* alert = [Uialertcontroller alertcontrollerwithtitle:@ "My alert"                               message:@ "This was an alert."                               Preferredstyle:uialertcontrollerstylealert]; uialertaction* DefaultAction = [uialertaction actionwithtitle:@ "OK" Style:uialertactionstyledefault   handler:^ ( Uialertaction * action) {}]; [Self Presentviewcontroller:alert animated:yes completion:nil];

In this case, create an alert in his class method:
AlertControllerWithTitle:message:preferredStyle:
, Preferredstyle defines the type of prompt box that is created, which is an enumeration value. You can choose a different cue box style.

The second class in the example: Uialertaction creates a behavior: the user clicks on a different button to trigger a different event. However, in the example, this behavior 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 way alert and action sheet were created changed: Created by Uialertcontroller. The previous Create alert method is still available in iOS8.         @since                *//Create an alert        uialertcontroller * alert = [Uialertcontroller alertcontrollerwithtitle:@] attention! "message:@" Your Device Haven ' t photolibrary. "Preferredstyle:uialertcontrollerstylealert";        Define action Events        uialertaction *action = [uialertaction actionwithtitle:@ "OK" style:uialertactionstylecancel handler:^ ( Uialertaction *action) {            NSLog (@ "Click the OK button after the callback");        }];        Add action time to the Cue box        [alert addaction:action];        Popup Notification box        [self Presentviewcontroller:alert animated:yes completion:nil];



The new wording of Uialertview and Uiactionsheet after iOS8.0

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.