IOS Uialertview (Warning box) method summary

Source: Internet
Author: User

Summary of common methods for Uialertview (warning box) in iOS
First, the method of initialization- (Instancetype) Initwithtitle: (NSString*) title message: (NSString*) message delegate: (ID /*<uialertviewdelegate>*/) Delegate Cancelbuttontitle: (NSString*) Cancelbuttontitle otherbuttontitles: (NSString*) Otherbuttontitles, ...;

This method creates a warning box by setting a title, content, proxy, and some button titles, and the code example is as follows:

Uialertview * alert = [[Uialertview alloc]initwithtitle:@ "My Warning Box" message:@ "This is a warning box" Delegate:self cancelbuttontitle:@ "    Cancel "otherbuttontitles:@" OK ", nil"; [Alert show];

The effect is as follows:


Note: If the number of buttons is more than two, it will be created like this:

If the number of buttons exceeds the screen display range, an effect similar to TableView will be created.


Second, attribute and method analysis


Title Property

@property(nonatomic,copy) nsstring *title;

Content Properties

@property(nonatomic,copy) nsstring *message;


Add a button that returns the index value of this button

-(Nsinteger) Addbuttonwithtitle: (nsstring *) title;

returns the button title according to the button index

-(nsstring *) Buttontitleatindex: (nsinteger) Buttonindex;

Get the number of buttons

@property(nonatomic,readonly) nsinteger numberofbuttons;

Set set a button to cancel button

@property (nonatomic) Nsinteger Cancelbuttonindex;

Returns the index value of the first of the other type buttons

@property (nonatomic,readonly) Nsinteger Firstotherbuttonindex;

Whether the warning box is visible

@property(nonatomic,readonly,getter=isvisible) BOOL visible;

Show Warning Box

-(void) show;

Code simulation Click Button Disappears Trigger method

-(void) Dismisswithclickedbuttonindex: (nsinteger) buttonindex animated: (BOOL) animated;

Set Alert box style

@property(nonatomic,assign) uialertviewstyle alertviewstyle;

The enumeration of styles is as follows

typedef ns_enum (Nsinteger, uialertviewstyle) {Uialertviewstyledefault = 0,//default Style uialertviewstylesecuretextinput,// Password input box style uialertviewstyleplaintextinput,//ordinary input frame style uialertviewstyleloginandpasswordinput//account password box style};

This method sets the index of the text input box

-(uitextfield *) Textfieldatindex: (nsinteger) Textfieldindex;


Threemethods in the Uialertviewdelegate

How to trigger when a button is clicked

-(void) Alertview: (uialertview *) Alertview clickedbuttonatindex: (nsinteger) buttonindex ;

The method to trigger when the warning box will be displayed

-(void) Willpresentalertview: (uialertview *) Alertview;

Method triggered when a warning box has been displayed

-(void) Didpresentalertview: (uialertview *) Alertview;

The method that is triggered when the warning box is going to disappear

-(void) Alertview: (uialertview *) Alertview willdismisswithbuttonindex: (nsinteger) Buttonindex;

Method that is triggered when the warning box has disappeared

-(void) Alertview: (uialertview *) Alertview diddismisswithbuttonindex: (nsinteger) Buttonindex;

Sets whether the first button is allowed instead of the Cancel button

-(BOOL) Alertviewshouldenablefirstotherbutton: (uialertview *) Alertview;



IOS Uialertview (Warning box) method summary

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.