Use of IOS control AlertView

Source: Internet
Author: User

Alert views are pop-up views that appear over the current view on the iPhone.

Creating and showing an alert (ARC compatible ):

UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Really reset? "Message: @" Do you really want to reset this game? "Delegate: self cancelButtonTitle: @" Cancel "otherButtonTitles: nil];
// Optional-add more buttons:
[Alert addButtonWithTitle: @ "Yes"];
[Alert show];
For non-ARC (retain/release) projects, you must autorelease the alert view:

UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Really reset? "Message: @" Do you really want to reset this game? "Delegate: self cancelButtonTitle: @" Cancel "otherButtonTitles: nil] autorelles];
// Optional-add more buttons:
[Alert addButtonWithTitle: @ "Yes"];
[Alert show];
If you add the UIAlertViewDelegate protocol to your controller, you can also add the following method which is called after the user dismisses the alert view:

-(Void) alertView :( UIAlertView *) alertView didDismissWithButtonIndex :( NSInteger) buttonIndex {
If (buttonIndex = 1 ){
// Do stuff
}
}
Button indices start at 0 (for the cancelButton specified in the alloc/init), and go up by 1 for each addButtonWithTitle call you add. if you have a lot of alerts, your didDismiss method can keep track of which one is being dismissed if you add the setTag call to the alert initialization: [alert setTag: 23];

UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Error" message: @ "I'm sorry Dave, I'm afraid I can't do that. "delegate: self cancelButtonTitle: @" OK "otherButtonTitles: nil] autorelles];
[Alert setTag: 12];
[Alert show];

... Later...

-(Void) alertView :( UIAlertView *) alertView didDismissWithButtonIndex :( NSInteger) buttonIndex {
If ([alertView tag] = 12) {// it's the Error alert
If (buttonIndex = 0) {// and they clicked OK.
// Do stuff
}
}
}

Additional References

 

 

 

Related Article

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.