注释的多个阵列,不同的引脚颜色为每个阵列? [英] Multiple Arrays of Annotations, Different Pin Color for Each Array?

查看:131
本文介绍了注释的多个阵列,不同的引脚颜色为每个阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序,foodannotations,gasannotations和shoppingannotations注释三个数组。我想说明的每个阵列展现出不同颜色的引脚。我目前使用

I have three arrays of annotations in my app, foodannotations, gasannotations, and shoppingannotations. I want each array of annotations to show a different colored pin. I am currently using

- (MKAnnotationView *)mapView:(MKMapView *)sheratonmap viewForAnnotation:(id<MKAnnotation>)annotation {
    NSLog(@"Welcome to the Map View Annotation");

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

    static NSString* AnnotationIdentifier = @"Annotation Identifier";
    MKPinAnnotationView* pinview = [[[MKPinAnnotationView alloc]
                                     initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];

    pinview.animatesDrop=YES;
    pinview.canShowCallout=YES;
    pinview.pinColor=MKPinAnnotationColorPurple;

    UIButton* rightbutton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightbutton setTitle:annotation.title forState:UIControlStateNormal];
    [rightbutton addTarget:self action:@selector(showDetails) forControlEvents:UIControlEventTouchUpInside];
    pinview.rightCalloutAccessoryView = rightbutton;

    return pinview;
}

我怎么可以设置此为使用三种不同的引脚颜色标注的​​每个阵列。

How can I set this up to use the three different pin colors for each array of annotations.

谢谢!

推荐答案

让你定义了实现在其中添加了一些识别哪些属性 MKAnnotation 协议的自定义类类型的注释它是什么?或者你定义了三个单独的类(每个类型的注释)的实现 MKAnnotation

Have you defined a custom class that implements the MKAnnotation protocol in which you added some property that identifies what kind of annotation it is? Or have you defined three separate classes (one for each type of annotation) that implement MKAnnotation?

假设你定义中,你在你的注释有一个名为 INT 物业说 annotationType 一个注释类类,那么您可以在做到这一点 viewForAnnotation

Assuming you've defined one annotation class in which you have an int property called say annotationType in your annotation class, then you can do this in viewForAnnotation:

int annType = ((YourAnnotationClass *)annotation).annotationType;
switch (annType)
{
    case 0 :   //Food
        pinview.pinColor = MKPinAnnotationColorRed;
    case 1 :   //Gas
        pinview.pinColor = MKPinAnnotationColorGreen;
    default :  //default or Shopping
        pinview.pinColor = MKPinAnnotationColorPurple;
}

结果
一对夫妇的其他东西:


A couple of other things:


  • 您应该使用<$c$c>dequeueReusableAnnotationViewWithIdentifier:方法

  • 而不是使用addTarget的:行动与自定义的方法来处理标注按钮preSS,使用地图视图的委托方法<一href=\"http://developer.apple.com/library/iOS/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/doc/uid/TP40008204-CH3-SW14\"><$c$c>calloutAccessoryControlTapped.在该委托方法,您可以使用 view.annotation 访问注释。

  • You should use the dequeueReusableAnnotationViewWithIdentifier: method
  • Instead of using addTarget:action and a custom method to handle the callout button press, use the map view's delegate method calloutAccessoryControlTapped. In that delegate method, you can access the annotation using view.annotation.

这篇关于注释的多个阵列,不同的引脚颜色为每个阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆