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