l [20] ve:无效的块类型?

时间:2010-10-20 11:12:35

标签: iphone nsurlconnection mkmapview

我不知道为什么我会收到这个错误。我也从以下代码中获得了EXC_BAD_ACCESS问题。有什么想法吗?

didRecieveResponsedidRecieveData以及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++;
    }
}

1 个答案:

答案 0 :(得分:0)

plistContentsData = [NSMutableData data];

您创建一个自动释放的NSMutableData对象,它可能在您退出didReceiveResponse方法后立即变为无效。您需要保留plistContentsData来修复该错误。