我不知道为什么我会收到这个错误。我也从以下代码中获得了EXC_BAD_ACCESS问题。有什么想法吗?
在didRecieveResponse
和didRecieveData
以及didFinishLoading
上运行断点会显示前两个运行时间,并在收到程序崩溃数据的中途显示。
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// starts... :)
plistContentsData = [NSMutableData data]; //NSMutableData - inst in head
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[plistContentsData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
mellowListings = [[NSArray alloc] initWithData:plistContentsData]; //NSArray - inst in head
NSLog(@"%@",mellowListings);
CLLocationCoordinate2D newLocation;
int counter = 0;
for(NSDictionary *tempDict in mellowListings){
NSLog(@"%f",([[tempDict objectForKey:@"lat"] floatValue]));
NSLog(@"%f",([[tempDict objectForKey:@"long"] floatValue]));
newLocation.latitude = ([[tempDict objectForKey:@"lat"] floatValue]);
newLocation.longitude = ([[tempDict objectForKey:@"long"] floatValue]);
TCPlaceMarker *placemark = [[TCPlaceMarker alloc] initWithCoordinate:newLocation];
placemark.title = [tempDict objectForKey:@"name"];
placemark.subtitle = [tempDict objectForKey:@"address1"];
placemark.source = [[tempDict objectForKey:@"source"] lowercaseString];
placemark.tag = counter;
[mapView addAnnotation:placemark];
counter++;
}
}
答案 0 :(得分:0)
plistContentsData = [NSMutableData data];
您创建一个自动释放的NSMutableData对象,它可能在您退出didReceiveResponse方法后立即变为无效。您需要保留plistContentsData
来修复该错误。