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