我正在使用MKReverseGeocoder (反向地理编码器)来检索用户的当前位置。我在CLLocation管理器的locationDidUpdatedToLocation方法中调用了反向地理编码器。
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if(!reverseGeocoder )
{
NSLog(@"geocoder is nill");
reverseGeocoder=[[MKReverseGeocoder alloc] initWithCoordinate:[newLocation coordinate]];
reverseGeocoder.delegate=self;
[reverseGeocoder start];
NSLog(@"geocoder allocated");
}
else
{
NSLog(@"geocoder is not nill");
if(reverseGeocoder.querying)
{
//do nothing ;
}
else
[reverseGeocoder release];
}
}.querying属性用于确保仅当已完成查询时,才应释放反向地理编码器。但当应用程序在运行后3-4秒内崩溃并显示错误消息时
-[MKReverseGeocoder isQuerying]: message sent to deallocated instance这里我漏掉了什么?
提前感谢您的帮助。
发布于 2011-09-14 22:23:51
会不会是因为您在发布地理编码器之前没有将它的委托设置为nil?还是因为你还没把指针钉上?
试试这个:
if(reverseGeocoder.querying)
{
//do nothing ;
}
else
{
[reverseGeocoder setDelegate:nil];
[reverseGeocoder release];
reverseGeocoder = nil;
}https://stackoverflow.com/questions/7417330
复制相似问题