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

发布于 2024-09-28 06:22:28 字数 1549 浏览 0 评论 0原文

我不知道为什么我会收到此错误。我还从以下代码中收到 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++;
    }
}

I don't know why I'm getting this error. I'm also getting an EXC_BAD_ACCESS issue from the following code. Any ideas why?

Running breakpoints on the didRecieveResponse and didRecieveData and didFinishLoading shows the first two get run and mid way through recieving data the program crashes.

- (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++;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唔猫 2024-10-05 06:22:28
plistContentsData = [NSMutableData data];

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

plistContentsData = [NSMutableData data];

You create an autoreleased NSMutableData object and it may become invalid right after you exit didReceiveResponse method. You need to retain plistContentsData to fix that error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文