l[20]ve:无效的块类型?
我不知道为什么我会收到此错误。我还从以下代码中收到 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++;
}
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您创建了一个自动释放的 NSMutableData 对象,它可能在您退出 didReceiveResponse 方法后立即变得无效。您需要保留
plistContentsData
来修复该错误。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.