Use of Uialertcontroller in IOS8

Source: Internet
Author: User

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

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.