更新时间:2023-01-26 23:31:03
您是否定义了一个实现 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
?
假设您已经定义了一个注释类,其中您的注释类中有一个名为 say annotationType
的 int
属性,那么您可以在 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:
dequeueReusableAnnotationViewWithIdentifier:
方法calloutAccessoryControlTapped
.在该委托方法中,您可以使用 view.annotation
访问注释.dequeueReusableAnnotationViewWithIdentifier:
methodcalloutAccessoryControlTapped
. In that delegate method, you can access the annotation using view.annotation
.