Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>NOTE:</strong></p> <p><strong>Important:</strong> UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert.</p> <p><a href="http://nshipster.com/uialertcontroller/" rel="nofollow noreferrer">Please check this out tutorial</a></p> <p><a href="https://stackoverflow.com/a/6967533/675170">"deprecated" means???</a></p> <blockquote> <p>Objectvie C</p> </blockquote> <p>.h file</p> <pre><code> @interface urViewController : UIViewController &lt;UIAlertViewDelegate&gt; { </code></pre> <p>.m file</p> <pre><code>// Create Alert and set the delegate to listen events UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Today's Entry Complete" message:@"Press OK to submit your data!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; // Set the tag to alert unique among the other alerts. // So that you can find out later, which alert we are handling alert.tag = 100; [alert show]; //[alert release]; -(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ // Is this my Alert View? if (alertView.tag == 100) { //Yes // You need to compare 'buttonIndex' &amp; 0 to other value(1,2,3) if u have more buttons. // Then u can check which button was pressed. if (buttonIndex == 0) {// 1st Other Button [self submitData]; } else if (buttonIndex == 1) {// 2nd Other Button } } else { //No // Other Alert View } } </code></pre> <blockquote> <p>Swift</p> </blockquote> <p>The Swifty way is to use the new UIAlertController and closures:</p> <pre><code> // Create the alert controller let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert) // Create the actions let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in NSLog("OK Pressed") } let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { UIAlertAction in NSLog("Cancel Pressed") } // Add the actions alertController.addAction(okAction) alertController.addAction(cancelAction) // Present the controller self.presentViewController(alertController, animated: true, completion: nil) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload