How can I dismiss UIAlertView?

Voloda2 picture Voloda2 · Feb 6, 2011 · Viewed 26.6k times · Source

How can I dismiss UIAlertView ? This code doesn't work.

@property (nonatomic, retain) UIAlertView *activityAlertView;
- (void)viewDidLoad 
{
self.activityAlertView = [[UIAlertView alloc] initWithTitle:@"Receiving data" message:@"\n\n"
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                                otherButtonTitles:nil, nil];  
[activityAlertView show];
}

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

-(void) myfunc
{
[self alertView:activityAlertView clickedButtonAtIndex:1];
}

Answer

JustSid picture JustSid · Feb 6, 2011

The - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated method of the UIAlertView class does what you want. eg:

[myAlertView dismissWithClickedButtonIndex:-1 animated:YES];