同一mapView中的几个不同的自定义图钉 [英] Several and different custom Pins in the same mapView

查看:91
本文介绍了同一mapView中的几个不同的自定义图钉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题....

我有一个mapView,我用几个自定义图钉填充了视图. 我会在mapView中使用不同的自定义图钉.

I have a mapView and i fill the view with several custom pins. I would different custom pins in my mapView.

我已经尝试过IF条件,但是没有用. 我不明白to方法的工作原理.

I have tried with an IF condition but don't work. I don't understand how the called to method works.

遵循代码. Vi alleil il codice.

Follow the code. Vi allego il codice.

//Customization of my pins
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation(id<MKAnnotation>)annotation{

    static NSString *identifier = @"";

    MKAnnotationView *pin = [ mappa dequeueReusableAnnotationViewWithIdentifier:identifier ];        

//OLD COORDINATES
    if(newcoordinate == FALSE){

        pin = [[[ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:identifier ]autorelease];
        pin.image = [ UIImage imageNamed:@"old.png" ]       
 } 

// NEW COORDINATES
    else ( newcoordinate == TRUE){
        pin = [[[ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:identifier ]autorelease];
        pin.image = [ UIImage imageNamed:@"new.png" ];
} 

    pin.canShowCallout = YES;

//CALLOUT INFO
    UIImage *image = [UIImage imageNamed:@"informations.png"];
    UIImageView *imgView = [[[UIImageView alloc] initWithImage:image]autorelease];
    pin.leftCalloutAccessoryView = imgView;

pin.annotation = annotation;

return pin;}

结果是...在相同的mapView中有多个图钉,但具有相同的自定义. :/

The result is... several pin in the same mapView but with the same customization. :/

谢谢.

推荐答案

已解决. 我在MyAnnotation类中添加了一个新属性:

SOLVED. I have added a new property in MyAnnotation class:

@interface MyAnnotation : NSObject <MKAnnotation>
{
    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle;
    BOOL isNew;  // <------- My solution    
}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, assign) BOOL isNew ; <--------- My solution

今天我已经了解了这些属性.

Today i have learned what are the properties.

这篇关于同一mapView中的几个不同的自定义图钉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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