i am working on a map application, in that i like to drop the pins (as in Zillow apps) when ever user change the map view. I am using following code code. i am try to load the xml data from server using NSAutoreleasepool to do the xml parsing in the background thread.
(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
NSLog(@"inside region did changed ");
urlString =[NSString stringWithFormat: @"http://asdfasdasdf.com/asdfasdf/mapxml.php]; [stories1 release]; [mapview removeAnnotations:eventPoints1]; eventPoints1 = [[NSMutableArray array] retain]; [self performSelectorInBackground:@selector(callParsing) withObject:nil];
}
-(void)callParsing{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self parseXMLFileAtURL:urlString];
[self performSelectorOnMainThread:@selector(droppingPin) withObject:nil waitUntilDone:YES];
[pool drain];
}
The above code is workin开发者_开发问答g fine, but once i changed the mapview, the appllication get crashed. Anyone can help me to fix the issue?
thanks in advance.
urlString is already autoreleased when it is returned from stringWithFormat. Since you are using urlString in callParsing which is executed on a different thread, you should pass it as an object to that method. Otherwise you risk it getting released before the callParsing method is executed and thus causing the crash:
...
[self performSelectorInBackground:@selector(callParsing:) withObject:urlString];
...
-(void)callParsing:(NSString*)urlString {
...
精彩评论