Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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:MKMapAnnotationView:当前位置与其他管脚具有相同的annotationView。如何让它独一无二?_Iphone_Annotations_Mkmapview - Fatal编程技术网

iPhone:MKMapAnnotationView:当前位置与其他管脚具有相同的annotationView。如何让它独一无二?

iPhone:MKMapAnnotationView:当前位置与其他管脚具有相同的annotationView。如何让它独一无二?,iphone,annotations,mkmapview,Iphone,Annotations,Mkmapview,我使用以下方法在我的mapView上显示MKAnnotation视图。但是wehn我做的是,用户的当前位置也被赋予与其他引脚相同的视图。如何使当前位置成为唯一的pin颜色 - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation { MKPinAnnotationView *annView=[[MKPinAnnotationV

我使用以下方法在我的mapView上显示MKAnnotation视图。但是wehn我做的是,用户的当前位置也被赋予与其他引脚相同的视图。如何使当前位置成为唯一的pin颜色

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] 
                                  initWithAnnotation:annotation 
                                  reuseIdentifier:@"currentloc"];
    //annView.pinColor = MKPinAnnotationColorGreen;

     UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     myDetailButton.frame = CGRectMake(0, 0, 23, 23);
     myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
     myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [myDetailButton addTarget:self 
                        action:nil/*@selector(checkButtonTapped:event:)*/ 
              forControlEvents:UIControlEventTouchUpInside];

    annView.rightCalloutAccessoryView = myDetailButton;

    annView.animatesDrop=NO;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
MKPinAnnotationView*annView=[[MKPinAnnotationView alloc]
initWithAnnotation:注释
重用标识符:@“currentloc”];
//annView.pinColor=MKPinAnnotationColorGreen;
UIButton*myDetailButton=[UIButton Button类型:UIButtonTypedTailButton];
myDetailButton.frame=CGRectMake(0,0,23,23);
myDetailButton.contentVerticalAlignment=uicontrolContentVerticalAlignment中心;
myDetailButton.contentHorizontalAlignment=uicontrolContentHorizontalAlignment中心;
[myDetailButton添加目标:自我
操作:nil/*@选择器(checkButtonTapped:事件:)*/
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView=myDetailButton;
annView.animatesDrop=否;
annView.canShowCallout=是;
annView.calloutOffset=CGPointMake(-5,5);
返回视图;
}

在注释的
视图中,检查注释是否是的实例。如果是,则返回
nil

if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;

您好,谢谢您的建议,我尝试了这个方法,但是我得到一个错误,上面写着“MKUserAnnotation undeclared”,我找到了它的[MKUserLocation class],而不是[MKUserAnnotation class]。谢谢,现在工作:@用户-如果这个答案帮助你或指导你正确的答案,你应该考虑接受它。哦,是的,这是我的错。应该是mkuserlocation谢谢大家的帮助与您的问题无关,但是:不要执行addTarget,而是在地图视图自己的calloutAccessoryControlTapped委托方法中处理按钮,该方法将提供注释的引用(参见示例)。另外,建议在viewForAnnotation中使用dequeueReusableAnnotationViewWithIdentifier来重用视图(参见示例)。谢谢Anna Karenina。我感谢你的意见。