Обновление UILabel-Subview от MKAnnotationview

У меня есть MapView с кластерными аннотациями (ADMapCluster). I want to show the amount of elements in the Clusterдля этого я добавляю UILabel в MKAnnotationView в качестве подпредставления.

Моя проблема в том, что когда я повторно использую MKAnnotationView после масштабирования или подобных действий, UILabel не обновляет текст.

- (MKAnnotationView *)mapView:(ADClusterMapView *)mapView viewForClusterAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

MKAnnotationView * pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADMapCluster"];
if (!pinView) {
    pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ADMapCluster"];
    pinView.image = [UIImage imageNamed:@"map-markers"];
    UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 5, 25, 20)];
    countLabel.textAlignment = NSTextAlignmentCenter;
    [countLabel setTag:2];
    countLabel.text = [NSString stringWithFormat:@"%d",[[(ADClusterAnnotation*)pinView.annotation originalAnnotations] count] ];
    countLabel.font = [UIFont fontWithName:@"Avenir-Book" size:10];
    [pinView addSubview:countLabel];

}
else {
    pinView.annotation = annotation;
    [((UILabel*)[pinView viewWithTag:2]) setText:[NSString stringWithFormat:@"%d",[[(ADClusterAnnotation*)pinView.annotation originalAnnotations] count] ]];
    [((UILabel*)[pinView viewWithTag:2]) setNeedsDisplay];
}
return pinView;

}

Есть идеи, что я делаю неправильно и почему ярлыки не обновляются?

0 ответов

Другие вопросы по тегам