Cancel UIAlertView programmatically

How can I cancel UIAlertView programmatically? This is the code I use to display a 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]; 
+7
source share
2 answers

Try using dismissWithClickedButtonIndex: as follows:

Here is the code to use:

 [myAlertView dismissWithClickedButtonIndex:-1 animated:YES]; 
+11
source

You can do it through

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

when the index of the "Cancel" button is called.

You can also simply remove the warning view from the supervisor (ie, " removeFromSuperview "). Make sure the " release " view is alloc'd in case you are not using ARC.

+4
source

All Articles