iOS Core note--uialertcontroller

Source: Internet
Author: User

1, Uialertcontroller Introduction:

※了解: Uialertcontroller-Box controller, used when you need to remind users to perform certain actions, usually in two styles: Intermediate Reminder box, bottom reminder box.

Apple Official Introduction: 2, Uialertcontroller use: 2-1, Uialertcontroller style:
    • 1. There are 2 styles of Uialertcontroller:

      As shown below :

2-2, Uialertcontroller use steps:
  1. Uialertcontroller use alertControllerWithTitle:message:preferredStyle: Create Uialertcontroller controller, and Set Reminder box reminder message, title, and alert box style;
  2. actionWithTitle:style:handler:create uialertaction by method;
  3. Alertcontroller call addAction: method to add action to Alertcontroller;
  4. The source controller invokes the presentViewController:animated:completion: method, showing the Alertcontroller as a modal form.
3, Uialertcontroller properties: 3-1, Uialertcontroller three major attributes:

※重要:The Preferredstyle property is a read-only property (that is: readOnly ).

3-2. Action property in Uialertcontroller:

※重要:Create a OK button, 一定要注意不能在提醒控制器的按钮的点击方法内部用到提醒控制器自己 you cannot put the following sentence inside the block; "Otherwise it will die loops, causing the warning controller to not be destroyed."

3-3. Add text Box Properties in Uialertcontroller:

※重要:Only the middle Reminder box style can add a text box, and the bottom reminder box cannot add a text box.

4, 2 Styles Example: 4-1, the middle reminder box:

Sample Program :

1.//MARK:-Create Uialertcontroller
2. Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "Warning" message:@ "Your account balance is not enough!" PreferredStyle: Uialertcontrollerstylealert];
3.
4.//MARK:-Set alert properties
5.//Alert.preferredstyle read-only attribute (readOnly)
6.//Alert.preferredstyle = Uialertcontrollerstylealert;
7.
8.//MARK:-Add text box
9. [Alert addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {
10.//1. Set placeholder text
Textfield.placeholder = @ "Please enter the recharge amount!";
12.}];
13.
//MARK:-Create button
Uialertaction *sure = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledestructive handler:^ ( Uialertaction * _nonnull action) {
16.//1. Get a text box with the Textfields property
NSString *text = [alert.textfields[0] text];
NSLog (@ "Your account has been credited:%@!", text);
19.}];
20.
Uialertaction *cancel = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ ( Uialertaction * _nonnull action) {
NSLog (@ "Your account is down!");
23.}];
24.
//MARK:-Add action
[Alert Addaction:sure];
[Alert Addaction:cancel];
28.
//MARK:-Show Reminder Box
[Self Presentviewcontroller:alert animated:yes completion:^{
31.
32.}];
4-2, the bottom of the reminder box example:

Sample Program :

1.//Uialertcontroller The default is Uialertcontrollerstyleactionsheet style created by Alloc, Init
2. Uialertcontroller *actionsheet = [[Uialertcontroller alloc] init];
3.
4.//MARK:-Set properties
5. Actionsheet.title = @ "Warning";
6. Actionsheet.message = @ "Your balance is not enough, please recharge it in time!";
7.
8.//MARK:-Read-only property
9.//Actionsheet.preferredstyle = Uialertcontrollerstyleactionsheet;
10.
One.//MARK:-Create button
Uialertaction *sure = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledestructive handler:^ ( Uialertaction * _nonnull action) {
NSLog (@ "Your account is down!");
14.}];
15.
Uialertaction *cancel = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ ( Uialertaction * _nonnull action) {
NSLog (@ "Your account has been paid!");
18.}];
19.
//MARK:-Add action
[Actionsheet Addaction:sure];
[Actionsheet Addaction:cancel];
23.
//MARK:-The bottom reminder box cannot add a text box
25.//[Actionsheet addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {
26.////1. Set placeholder text
27.//Textfield.placeholder = @ "Please enter the recharge amount!";
28.//}];
29.
30.
//MARK:-Display the Reminder box at the bottom
[Self Presentviewcontroller:actionsheet animated:yes completion:^{
33.
34.}];

iOS Core note--uialertcontroller

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.