1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Dismissing UIAlertView without pressing button

Discussion in 'Mac Programming' started by ace2600, Apr 6, 2008.

  1. macrumors member

    #1
    Hi,

    How do I dismiss a UIAlertView without a Cancel or any other button being pressed?
     
  2. macrumors 65816

    Sbrocket

    #2
    I'm not sure if this is correct, but you might be able to close it by calling this:

    -[UIModalView dismissWithClickedButtonIndex:animated:]

    Take a look at the docs on that (UIModalView is the superclass of UIAlertView) and see if it works.
     
  3. macrumors member

    #3
    Thanks! That worked.

    I had read the UIModalView methods, but didn't think about calling this manually (as opposed to being triggered by the cancel button).

    If anyone is interested in the code:
    Code:
    //Create UIAlertView alert
    alert = [[UIAlertView alloc] initWithTitle:@"Alert Title" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
    
    //In another function
    [alert dismissWithClickedButtonIndex:0 animated:TRUE];
     
  4. macrumors 65816

    Sbrocket

    #4
    Yeah, I thought at first from reading the description (that could probably be changed a bit) that it sounded like it should be a delegate method or something, but it wasn't marked as such so might as well give it a try. Its probably set as the action for a UIControlEventTouchUpInside on the buttons when the view is created, but I can't see any side effects to calling it directly.
     

Share This Page