Several and different custom Pins in the same mapView

半腔热情 提交于 2019-12-12 01:12:25

问题


This is my question....

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

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

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;}

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

Thank you.


回答1:


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.



来源:https://stackoverflow.com/questions/8459085/several-and-different-custom-pins-in-the-same-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!