我继承了一个抛出此警告的项目
Incompatible pointer types assigning to 'MKPinAnnotationView *' from 'MKAnnotationView *'在这条线上
pinView=[[[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];
}我想在没有警告的情况下退还这个项目,所以我希望这里的人能迅速得到答复
完整代码:
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
NSUserDefaults *prefs=[NSUserDefaults standardUserDefaults];
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (!pinView) {
pinView=[[[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];
}
}
pinView.animatesDrop=YES;
[mapView.userLocation setTitle:@"I am here"];
[mapView.userLocation setSubtitle:[prefs objectForKey:@"CurrentLocationName"]];
return pinView;
}谢谢!
发布于 2012-05-08 21:23:42
pinView变量被声明为MKPinAnnotationView,但该行创建了一个MKAnnotationView。
更改此行:
pinView=[[[MKAnnotationView alloc]initWithAnnotation...至:
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation...您还应该拥有该if的else部件,以处理批注视图的重用:
else
pinView.annotation = annotation;发布于 2012-05-08 21:21:14
您正在使用pin注释视图,同时您正在将注释视图分配为pinview,这在技术上是错误的!我猜这就是它发出警告的原因。试试这个可能会解决你的问题。
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id <MKAnnotation>)annotation {
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (!pinView) {
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];
}
..........
..........
}https://stackoverflow.com/questions/10499226
复制相似问题