Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cancel UIAlertView programmatically

How can I cancel a UIAlertView programmatically? This is the code that I use to show the UIAlertView

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Save Background" message:@"Downloading..." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
    CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 70.0);
    [myAlertView setTransform:myTransform];
    [myAlertView show];
like image 254
atomikpanda Avatar asked Aug 09 '12 16:08

atomikpanda


2 Answers

Try to use dismissWithClickedButtonIndex: like this:

Here is the code to use:

[myAlertView dismissWithClickedButtonIndex:-1 animated:YES];
like image 138
Justin Boo Avatar answered Oct 22 '22 22:10

Justin Boo


You could do it via

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

while calling the "cancel" button index.

You could also simply remove the alert view from the superview (i.e. "removeFromSuperview"). Make sure to "release" the alloc'd view in case you are not using ARC.

like image 4
Michael Dautermann Avatar answered Oct 22 '22 23:10

Michael Dautermann