1. Title
Obtain or set the title on uialertview.
2. Message
Get or set messages on uialertview
Uialertview * alertview = [[uialertview alloc] initwithtitle: @ "title" message: @ "message" delegate: Self cancelbuttontitle: @ "cancel" otherbuttontitles: @ "OK", nil];
Alertview. Title = @ "T ";
Alertview. Message = @ "M ";
[Alertview show];
3. numberofbuttons (read-only)
Returns the number of buttons on the uialertview.
Uialertview * alertview = [[uialertview alloc] initwithtitle: @ "title" message: @ "message" delegate: Self cancelbuttontitle: @ "cancel" otherbuttontitles: @ "OK", nil];
Nslog (@ "% d", alertview. numberofbuttons );
[Alertview show];
4. cancelbuttonindex
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "prompt" message: @ "Please select a button:" delegate: Nil cancelbuttontitle: @ "cancel" otherbuttontitles: @ "button 1", @ "button 2", @ "button 3", nil];
[Alert show];
Nslog (@ "the badge of the cancel button in uialertview is % d", alert. cancelbuttonindex );
Effect:
Do not consider that the badge of the cancel button is 4, "cancel", "button 1", "button 2", and "button 3" indexes buttonindex are 0, 1, 2, and 3, respectively.
5. alertviewstyle5.1 uialertviewstyleloginandpasswordinput
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "product information display" message: P. name delegate: Nil cancelbuttontitle: @ "cancel" otherbuttontitles: @ "OK", nil];
Alert. alertviewstyle = uialertviewstyleloginandpasswordinput;
// The uialertview is displayed.
[Alert show];
5.2 uialertviewstyleplaintextinput
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "product information display" message: P. name delegate: Nil cancelbuttontitle: @ "cancel" otherbuttontitles: @ "OK", nil];
Alert. alertviewstyle = uialertviewstyleplaintextinput;
// The uialertview is displayed.
[Alert show];
5.3 uialertviewstylesecuretextinput
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "product information display" message: P. name delegate: Nil cancelbuttontitle: @ "cancel" otherbuttontitles: @ "OK", nil];
Alert. alertviewstyle = uialertviewstylesecuretextinput;
// The uialertview is displayed.
[Alert show];
6.-(uitextfield *) textfieldatindex :( nsinteger) textfieldindex
Return the text box corresponding to the textfieldindex badge.
Retrieve text in text box
7. Manual cancellation dialog box
[Alert dismisswithclickedbuttonindex: 0 animated: Yes];
8. Delegate
As a proxy for uialertview, you must comply with uialertviewdelegate.
1. When you click the button on uialertview, it is called. After the method is called, uialertview disappears automatically.
-(Void) alertview :( uialertview *) alertview clickedbuttonatindex :( nsinteger) buttonindex;
2. When uialertview is about to appear, call
-(Void) willpresentalertview :( uialertview *) alertview;
3. Call When uialertview appears completely
-(Void) didpresentalertview :( uialertview *) alertview;
4. Call When uialertview is about to disappear
-(Void) alertview :( uialertview *) alertview willdismisswithbuttonindex :( nsinteger) buttonindex;
5. Call when the uialertview disappears completely
-(Void) alertview :( uialertview *) alertview diddismisswithbuttonindex :( nsinteger) buttonindex;
9. Note that when uialertview calls show to display it, the system will automatically reference it and it will not be released. 10. Add a subview for uialertview
When adding a sub-view to a uialertview object too much, you must note that if you delete the button, that is, when you cancel all the buttons in the uialerview, the entire display structure may be unbalanced. The space occupied by the buttons will not disappear. We can also understand that these buttons are not actually deleted, but they are invisible. If the uialertview object is only used to display text, you can add a linefeed (@ "\ n) at the beginning of the message to balance the space at the bottom and top of the button.
The following code demonstrates how to add a subview to a uialertview object.
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "Please wait" message: Nil delegate: Nil cancelbuttontitle: Nil otherbuttontitles: Nil];
[Alert show];
Uiactivityindicatorview * activeview = [[uiactivityindicatorview alloc] initwithactivityindicatorstyle: uiactivityindicatorviewstylewhitelarge];
Activeview. Center = cgpointmake (alert. bounds. Size. width/2.0f, alert. bounds. Size. Height-40366f );
[Activeview startanimating];
[Alert addsubview: activeview];
11. Small Example of uialertview
Uialertview by default, all texts are centered and aligned. What should I do if I want to align the text to the left or add other controls, such as an input box? Don't worry, the iPhone SDK is still flexible, and there are a lot of delegate messages for calling programs. All you need to do is
-(Void) willpresentalertview :( uialertview *) alertview
Modify or add the message as needed. For example, to align the message text left, the following code can be implemented:
-(Void) willpresentalertview :( uialertview *) alertview
{
For (uiview * view in alertview. subviews)
{
If ([view iskindofclass: [uilabel class])
{
Uilabel * label = (uilabel *) view;
Label. textalignment = uitextalignmentleft;
}
}
}
Briefly describe the properties and usage of uialertview