The Uialertcontroller in iOS8 includes the previous Uialertview and Uiactionsheet, which are assembled into their own style;
1------------Uialertcontrollerstylealert-----The original Uialertview
Uialertcontroller *ALERTC = [Uialertcontroller alertcontrollerwithtitle:@ "ALERTC" message:@ "message" PreferredStyle: Uialertcontrollerstylealert];
preferredstyle--Read Only
Print the type of the selected Alertcontroller actionsheet--0 alertview--1
NSLog (@ "%ld", Alertc.preferredstyle);
Get the title and information for ALERTC
NSLog (@ "%@", alertc.title);
NSLog (@ "%@", alertc.message);
Change title
Alertc.title = @ "title change";
Add Event Execution button Actiontitle directly to ALERTC (only one can be added)
/*
[ALERTC addaction:[uialertaction actionwithtitle:@ "Actiontitle" Style:uialertactionstyledefault handler:^ ( Uialertaction *action) {
The callback method when you click Actiontitle
}]];
*/
Add multiple buttons
Without any agent, when we click on the button in the Alertview interface, we do not need to use Buttonindex to distinguish which button we click, and when there are multiple alertview on an interface, There is no need to use the tag value to distinguish which button on the alertview you clicked.
This facilitates our logical thinking, but the amount of code does not decrease
Uialertaction *action = [uialertaction actionwithtitle:nslocalizedstring (@ "cancle" @ "cancle action")
Style:uialertactionstylecancel
handler:^ (Uialertaction *action) {
Cancle code that corresponds to execution
NSLog (@ "cancle action");
}];
Uialertaction *action1 = [uialertaction actionwithtitle:nslocalizedstring (@ "Sure" @ "sure action")
Style:uialertactionstyledefault
handler:^ (Uialertaction *action) {
Sure code that corresponds to execution
NSLog (@ "sure action");
}];
[ALERTC addaction:action];
[ALERTC Addaction:action1];
Alertview input Box sheet type No but sheet type Uialertcontroller can be added TextField when the user wants to display sheet, the program will collapse
[ALERTC addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {
Textfield.placeholder = @ "textfiled";
}];
Here, whether Alertview or Actionsheet is a separate cotroller, it is necessary to show our Alertview or Actionsheet by Presentviewcontroller.
[Self PRESENTVIEWCONTROLLER:ALERTC animated:yes completion:nil];
2---------------uialertcontrollerstyleactionsheet----the original Uiactionsheet
Uialertcontroller *ALERTC = [Uialertcontroller alertcontrollerwithtitle:@ "ALERTC" message:@ "message" PreferredStyle: Uialertcontrollerstyleactionsheet];
Uialertaction *action = [uialertaction actionwithtitle:nslocalizedstring (@ "cancle" @ "cancle action")
Style:uialertactionstylecancel
handler:^ (Uialertaction *action) {
NSLog (@ "cancle action");
}];
Uialertaction *action1 = [uialertaction actionwithtitle:nslocalizedstring (@ "Sure" @ "sure action")
Style:uialertactionstyledefault
handler:^ (Uialertaction *action) {
NSLog (@ "sure action");
}];
[ALERTC addaction:action];
[ALERTC Addaction:action1];
[Self PRESENTVIEWCONTROLLER:ALERTC animated:yes completion:nil];
Use of Uialertcontroller in IOS8