【发布时间】:2011-05-27 01:40:14
【问题描述】:
我正在尝试将不同的图像添加到不同的注释视图中,换句话说,我想要一个独特的图片来对应每个独特的图钉。这是我正在尝试的:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
if (CLLocationCoordinate2D == theCoordinate1) {
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Jeff.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];
}else if(CLLocationCoordinate2D = theCoordinate2) {
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Pierce.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];
}
我写的那行出错了
if (CLLocationCoordinate2D == theCoordinate1) {
我不太确定出了什么问题,我也想不出另一种方法来识别单个注释。非常感谢任何帮助!
【问题讨论】:
-
杰夫,欢迎来到 SO!尽量避免在代码粘贴中使用制表符 - 尝试使用空格来代替 - 让您的代码在您的问题中正确格式化。那么帮助你就容易多了!
标签: ios mapkit mkmapview mkannotation