Transferred from: My.oschina.net/u/2340880/blog/408873?p=1
- 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, ...;
- Second, attribute and method analysis
- Three, the method in Uialertviewdelegate
Uialertview (warning Box) common methods in iOS summary one, initialize Method-(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:@"我的警告框" message:@"这是一个警告框" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", 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,//默认风格 UIAlertViewStyleSecureTextInput,//密码输入框风格 UIAlertViewStylePlainTextInput,//普通输入框风格 UIAlertViewStyleLoginAndPasswordInput//账号密码框风格};
This method sets the index of the text input box
-(Uitextfield *) Textfieldatindex: (Nsinteger) Textfieldindex;
Three, the method in 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