MKAnnotation 遇到问题。有一个自定义的 pinview 并且在第一次加载时工作正常。去移除别针,然后重新加载它们改变颜色的相同别针。我添加了来自两个不同数据库的引脚并且工作得很好。一旦删除然后分别添加每个阵列,第二个阵列将采用第一个阵列自定义引脚而不是分配的引脚。
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"pin";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stores.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
NSString *badgestringss = @"8 reviews";
customBadge1 = [CustomBadge customBadgeWithString:badgestringss
withStringColor:[UIColor whiteColor]
withInsetColor:RGB(255, 51, 0)
withBadgeFrame:YES
withBadgeFrameColor:[UIColor whiteColor]
withScale:1.0
withShining:YES];
[customBadge1 setFrame:CGRectMake(100, 1, 85, 15)];
[pinView.leftCalloutAccessoryView addSubview:customBadge1];
if(setStoreOrShops==NO){
pinView.image = [UIImage imageNamed:@"stores.png"]; //as suggested by Squatch
}
else if (setStoreOrShops==YES){
pinView.image = [UIImage imageNamed:@"shops.png"];
}
else {
[mapView.userLocation setTitle:@"Current Location"];
}
}
return pinView;
}
已经到处搜索,但似乎无法找到一个可以工作的例子或一个问题所在的想法。谢谢你的帮助。