Dismissing UIAlertView without pressing button

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

  1. macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #1
    Hi,

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

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #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. thread starter macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #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

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #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