iOS Developer Library

Developer

UIKit Framework Reference UIAlertViewDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIAlertViewDelegate

Important: UIAlertViewDelegate is deprecated in iOS 8. (Note that UIAlertView is also deprecated.) To create and manage alerts in iOS 8 and later, use UIAlertController. More...

Inheritance


Not Applicable

Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 2.0 and later.
  • Sent to the delegate when the user clicks a button on an alert view.

    Declaration

    Swift

    optional func alertView(_ alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)

    Objective-C

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

    Parameters

    alertView

    The alert view containing the button.

    buttonIndex

    The index of the button that was clicked. The button indices start at 0.

    Discussion

    The receiver is automatically dismissed after this method is invoked.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate to determine whether the first non-cancel button in the alert should be enabled.

    Declaration

    Swift

    optional func alertViewShouldEnableFirstOtherButton(_ alertView: UIAlertView) -> Bool

    Objective-C

    - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView

    Parameters

    alertView

    The alert view that is being configured.

    Return Value

    YEStrue if the button should be enabled, no if the button should be disabled.

    Import Statement

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Sent to the delegate before a model view is presented to the user.

    Declaration

    Swift

    optional func willPresentAlertView(_ alertView: UIAlertView)

    Objective-C

    - (void)willPresentAlertView:(UIAlertView *)alertView

    Parameters

    alertView

    The alert view that is about to be displayed.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate after an alert view is presented to the user.

    Declaration

    Swift

    optional func didPresentAlertView(_ alertView: UIAlertView)

    Objective-C

    - (void)didPresentAlertView:(UIAlertView *)alertView

    Parameters

    alertView

    The alert view that was displayed.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate before an alert view is dismissed.

    Declaration

    Swift

    optional func alertView(_ alertView: UIAlertView, willDismissWithButtonIndex buttonIndex: Int)

    Objective-C

    - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

    Parameters

    alertView

    The alert view that is about to be dismissed.

    buttonIndex

    The index of the button that was clicked. The button indices start at 0. If this is the cancel button index, the alert view is canceling. If -1, the cancel button index is not set.

    Discussion

    This method is invoked before the animation begins and the view is hidden.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate after an alert view is dismissed from the screen.

    Declaration

    Swift

    optional func alertView(_ alertView: UIAlertView, didDismissWithButtonIndex buttonIndex: Int)

    Objective-C

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

    Parameters

    alertView

    The alert view that was dismissed.

    buttonIndex

    The index of the button that was clicked. The button indices start at 0. If this is the cancel button index, the alert view is canceling. If -1, the cancel button index is not set.

    Discussion

    This method is invoked after the animation ends and the view is hidden.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate before an alert view is canceled.

    Declaration

    Swift

    optional func alertViewCancel(_ alertView: UIAlertView)

    Objective-C

    - (void)alertViewCancel:(UIAlertView *)alertView

    Parameters

    alertView

    The alert view that will be canceled.

    Discussion

    If the alert view’s delegate does not implement this method, clicking the cancel button is simulated and the alert view is dismissed. Implement this method if you need to perform some actions before an alert view is canceled. An alert view can be canceled at any time by the system—for example, when the user taps the Home button. The alertView:willDismissWithButtonIndex: and alertView:didDismissWithButtonIndex: methods are invoked after this method.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.