Search code examples
iosobjective-cnsurlconnectionuialertviewuiactivityindicatorview

How to dismiss alert view after a successful NSURL connection


I have an UIAlertView with the UIActivityIndicatorView.

UIAlertView *alertView_Spinning = 
   [[UIAlertView alloc] initWithTitle:@"Please wait" 
                              message:@"Connecting to server" 
                             delegate:nil 
                    cancelButtonTitle:nil 
                    otherButtonTitles: nil];
alertView_Spinning.tag=0;

UIActivityIndicatorView *indicator = 
  [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];

[alertView_Spinning setValue:indicator forKey:@"accessoryView"];
[alertView_Spinning show];

How can I dismiss this alert from the below method:Can I use alert tag for dismissing?. I am not including any buttons in my alert view.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    //dismiss alert view here
}

Solution

  • You should assign it to an ivar or property of your current class instead of as a local variable, then call dismissWithClickedButtonIndex:animated: in the connectionDidFinishLoading: handler.