我有一个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 …Run Code Online (Sandbox Code Playgroud)