问题
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