Хорошо, у меня есть несколько пинов на карте.Эти значки показывают различные типы аттракционов.(Например, парки, фермы и т. Д.)
Я хочу добавить пользовательские изображения для этих различных типов булавок.Парки имеют имидж парка и наоборот.
Однако, когда я добавил, не все изображения отображаются успешно.Например, в парках у него должно быть 5 контактов, но изображение выводится только в 2 выводах, тогда как в остальных 3 используются красные выводы по умолчанию.
Но если бы я использовал цвета, чтобы различать их.Например, [pinsetPinColor:MKPinAnnotationColorGreen];
Работает!Кто-нибудь знает в чем проблема?
Соответствующие коды приведены ниже.Скажи мне, если тебе нужно больше.спасибо!
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:MKUserLocation.class]) {
//user location view is being requested,
//return nil so it uses the default which is a blue dot...
return nil;
}
//NSLog(@"View for Annotation is called");
MKPinAnnotationView *pin=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:nil];
pin.userInteractionEnabled=TRUE;
MapEvent* event = (MapEvent*)annotation;
NSLog(@"thetype: %@", event.thetype);
if ([event.thetype isEqualToString:@"adv"]) {
//[pin setPinColor:MKPinAnnotationColorGreen];
pin.image = [UIImage imageNamed:@"padv.png"];
}
else if ([event.thetype isEqualToString:@"muse"]){
//[pin setPinColor:MKPinAnnotationColorPurple];
pin.image = [UIImage imageNamed:@"pmuse.png"];
}
else if ([event.thetype isEqualToString:@"nightlife"]){
pin.image = [UIImage imageNamed:@"pnight.png"];
}
else if ([event.thetype isEqualToString:@"parks"]){
pin.image = [UIImage imageNamed:@"ppark.png"];
}
else if ([event.thetype isEqualToString:@"farms"]){
pin.image = [UIImage imageNamed:@"pfarm.png"];
}
else {
[pin setPinColor:MKPinAnnotationColorRed];
}
pin.canShowCallout = YES;
pin.animatesDrop = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(clickAnnotation:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:event.uniqueID forState:UIControlStateNormal];
pin.rightCalloutAccessoryView = rightButton;
return pin;
}