我有一个带有集群注释的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;
}
知道我做错了什么以及为什么标签没有更新?