Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dismiss UIAlertView?

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];
}
like image 854
Voloda2 Avatar asked Feb 06 '11 18:02

Voloda2


2 Answers

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

[myAlertView dismissWithClickedButtonIndex:-1 animated:YES];
like image 63
JustSid Avatar answered Oct 15 '22 01:10

JustSid


Since you are using a delegate callback method of UIAlertView, I think it is better you use the following code

[myAlertView dismissWithClickedButtonIndex:0 animated:YES]; 

if not then use the above suggested code

[myAlertView dismissWithClickedButtonIndex:-1 animated:YES];
like image 31
Sertorio Noronha Avatar answered Oct 15 '22 00:10

Sertorio Noronha