【发布时间】:2011-01-17 08:11:54
【问题描述】:
好的,我在 mapkit 上有很多图钉。这些图钉显示不同类型的景点。 (例如公园、农场等)
我想为这些不同类型的图钉添加自定义图像。公园有公园形象,反之亦然。
但是,当我添加时,并非所有图像都成功显示。例如,在公园里,它应该有 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;
}
【问题讨论】:
标签: iphone xcode annotations mapkit