Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone MKPinAnnotationView与MKAnnotationView_Iphone_Mkmapview_Mkannotationview_Mkpinannotationview - Fatal编程技术网

Iphone MKPinAnnotationView与MKAnnotationView

Iphone MKPinAnnotationView与MKAnnotationView,iphone,mkmapview,mkannotationview,mkpinannotationview,Iphone,Mkmapview,Mkannotationview,Mkpinannotationview,我继承了一个抛出此警告的项目 Incompatible pointer types assigning to 'MKPinAnnotationView *' from 'MKAnnotationView *' 在这条线上 pinView=[[[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease]; } 我想在没有任何警告的情况下归还这个项目,所以我希

我继承了一个抛出此警告的项目

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;        
}
-(MKAnnotationView*)地图视图:(MKMapView*)mV视图用于注释:(id)注释{
MKPinAnnotationView*pinView=nil;
NSUserDefaults*prefs=[NSUserDefaults standardUserDefaults];
if(注释!=mapView.userLocation)
{
静态NSString*defaultPinID=@“com.invasivecode.pin”;
pinView=(MKPinAnnotationView*)[mapView出列重用AnnotationViewWithIdentifier:defaultPinID];
如果(!pinView){
pinView=[[MKAnnotationView alloc]initWithAnnotation:annotation重用标识符:defaultPinID]autorelease];
}
}   
pinView.animatesDrop=是;
[mapView.userLocation setTitle:@“我在这里”];
[mapView.userLocation setSubtitle:[prefs objectForKey:@“CurrentLocationName”];
返回pinView;
}

谢谢

您正在取消pin注释视图的标题,同时将注释视图分配为您的pin视图,这在技术上是错误的!!!我想这就是它发出警告的原因。试试这个可以解决你的问题

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id  <MKAnnotation>)annotation {


pinView = (MKPinAnnotationView *)[mapView  dequeueReusableAnnotationViewWithIdentifier:defaultPinID];


if (!pinView) {
        pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];
    }

..........
..........

}
-(MKAnnotationView*)地图视图:(MKMapView*)mV视图用于注释:(id)注释{
pinView=(MKPinAnnotationView*)[mapView出列重用AnnotationViewWithIdentifier:defaultPinID];
如果(!pinView){
pinView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:defaultPinID]autorelease];
}
..........
..........
}

变量
pinView
声明为
MKPinAnnotationView
,但该行创建了一个
MKAnnotationView

更改此行:

pinView=[[[MKAnnotationView alloc]initWithAnnotation...
致:


如果要处理注释视图的重复使用,您还应该在
if
中添加
else
部分:

else
    pinView.annotation = annotation;
else
    pinView.annotation = annotation;