Я написал код для отображения аннотаций с пользовательскими изображениями в режиме просмотра карты. Мой делегат mapview реализует этот метод для настройки аннотаций, когда они помещаются на карту:
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation {
if ([annotation isKindOfClass:[Station class]]) {
Station *current = (Station *)annotation;
MKPinAnnotationView *customPinview = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
if([[current type] compare:FONTANELLA]==NSOrderedSame)
customPinview.pinColor = MKPinAnnotationColorPurple;
else{
int test=current.bici;
if(test==0)
customPinview.image = [UIImage imageNamed:@"bicimir.png"];
else if(test<4)
customPinview.image = [UIImage imageNamed:@"bicimi.png"];
else if(test>=4)
customPinview.image = [UIImage imageNamed:@"bicimig.png"];
}
customPinview.animatesDrop = NO;
customPinview.canShowCallout = YES;
return customPinview;
}
else{
NSString *identifier=@"MyLocation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
return annotationView;
}
}
Проблема заключается в странном поведении, когда я долго нажимаю на пользовательскую аннотацию на карте: изменяется изображение и отображается красный значок по умолчанию.
Почему такое поведение? И как этого избежать?