1

I want to resign UIAlertView containing activity indicator. I am putting following code. It is working while loading data but the UIalertview is not resigning after successful parsing. What condition should I give here???

   - (void) updateFilterProgress{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Loading..."      message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]       initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height   - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[pool release];
}

ON my button click event I put following code

     // **EDIT==1**
      [NSThread detachNewThreadSelector:@selector(updateFilterProgress) toTarget:self withObject:nil];toTarget:self withObject:nil];                                //for calling updateFilterProgress


        NSString *url = [NSString   stringWithFormat:@"http://....url...../hespdirectory/phpsqlsearch_genxml.php?lat=%f&radius=%f&lng=%f",lati,longi,radius];
//NSLog(@"NSString *url");
NSLog(@"%@", url);

//NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)

{   **//EDIT==2**

    [alert dismissWithClickedButtonIndex:0 animated:YES];     //for resigning alertview 

    for (int i = 0; i < [appDelegate.markers count]; i++)
{

    //marker *aMarker = [[marker alloc] init];
    marker *aMarker = [appDelegate.markers objectAtIndex:i];
    location.latitude = [aMarker.lat floatValue];
    location.longitude =[aMarker.lng floatValue];
    AddressAnnotation *annobj = [[AddressAnnotation alloc] initWithCoordinate:location];

    annobj.title = aMarker.name;
    [mapView addAnnotation:annobj];
    [annobj release];
         }
 }

I want to resign this UIAlertView containing activity indicator.......

Navnath Memane
  • 265
  • 1
  • 8
  • 25

1 Answers1

1

Set your UIAlertView and ActivityIndicator (and all objects inside the alert view) as members of your class file.

Then, where you'd normally release these items (and where you want to dismiss the alert) you can call this:

[myAlertView dismissWithClickedButtonIndex:0 animated:YES];

This has the same effect as if though the user clicked the cancel button on it, which is perfectly acceptable.

Hope this helps!

Luke
  • 11,426
  • 43
  • 60
  • 69
  • Yes I put this code in if(success) { [alert dismissWithClickedButtonIndex:0 animated:YES]; } but it is not working. – Navnath Memane Oct 18 '11 at 13:20
  • I have followed this link http://stackoverflow.com/questions/7282632/ios-setting-progress-bar-value-while-images-are-being-processed and inserted my UIAlertview in - (void) updateFilterProgress. to show progress while buffering. Now the same I want to resign after progess – Navnath Memane Oct 18 '11 at 13:33
  • Are you sure that the cancel check you are performing gets hits? Place an NSLog or breakpoint inside and see what happens. Or is something else getting in the way? Where do you currently release the alert and it's contained objects? – Luke Oct 18 '11 at 13:59
  • Yes it is stoping on breakpoint but still it is not resigning on the code. The total code I have pasted above. Is there anything remaining – Navnath Memane Oct 18 '11 at 14:09
  • But where exactly are you calling my line of code? Can you edit your posted code with exactly what you are doing? – Luke Oct 18 '11 at 16:20
  • I have edited code..........see below the line EDIT==1, EDIT==2. I have put this code in my program but not working. So I have updated above. Can you check plz... – Navnath Memane Oct 18 '11 at 17:42