我有一个条件语句来在下面的方法中添加地图注释图标/图钉。我遇到的问题是地图上填充了所有相同的图标。它应该检测猫 ID 并根据检测到的猫 ID 显示图标。我不确定问题出在哪里,因为这在 iOS 6 中确实有效,现在在 iOS 7 中,地图只显示所有相同的注释图标图像。
- (MKAnnotationView *) mapView:(MKMapView *)mapingView viewForAnnotation:(id <MKAnnotation>) annotation {
annView = nil;
if(annotation != mapingView.userLocation)
{
static NSString *defaultPinID = @"";
annView = (MKAnnotationView *)[mapingView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( annView == nil )
annView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annView.rightCalloutAccessoryView = rightButton;
MyAnnotation* annotation= [MyAnnotation new];
annotation.catMapId = categoryIdNumber;
NSLog(@"categoryIdNumber %@",categoryIdNumber);
NSLog(@"annotation.catMapId %@",annotation.catMapId);
if (annotation.catMapId == [NSNumber numberWithInt:9]) {
annView.image = [UIImage imageNamed:@"PIN_comprare.png"];
NSLog(@"annview 9");
}
else if (annotation.catMapId == [NSNumber numberWithInt:10]) {
annView.image = [UIImage imageNamed:@"PIN_mangiare.png"];
NSLog(@"annview 10");
}
else if (annotation.catMapId == [NSNumber numberWithInt:11]) {
annView.image = [UIImage imageNamed:@"PIN_visitare.png"];
NSLog(@"annview 11");
}
else if (annotation.catMapId == [NSNumber numberWithInt:12]) {
annView.image = [UIImage imageNamed:@"PIN_vivere.png"];
NSLog(@"annview 12");
}
annView.canShowCallout = YES;
}
return annView;
}