【问题标题】:Clustering annotations won't work聚类注释不起作用
【发布时间】:2013-12-26 01:41:50
【问题描述】:

今天我开始使用 ADClusterMapView (https://github.com/applidium/ADClusterMapView) 并研究了示例项目...所以我决定将内容添加到我的项目中...一切正常,没有红色错误...模拟器打开并发布了一个帖子......我试图找出问题几个小时......所以也许你知道问题出在哪里......

-(void)viewDidLoad {

   [ADClusterMapView class];
   NSArray* airports = [Airport allAirports];
   [mapView setAnnotations:airports];
   [mapView setVisibleMapRect:MKMapRectWorld];
}

-(MKAnnotationView*)mapView:(MKMapView *)aMapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString* reuseIdentifier = @"airportAnnotation";

    if ([annotation isKindOfClass:[Airport class]]) {
        MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
        if (!annotationView) {
            annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier] autorelease];
            annotationView.canShowCallout = YES;
    }
        annotationView.image = ((Airport*)annotation).icon;
        return annotationView;
    }
}


- (MKAnnotationView *)mapView:(ADClusterMapView *)aMapView viewForClusterAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView * annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADMapCluster"];
if (!annotationView) {
    annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                            reuseIdentifier:@"ADMapCluster"]
               autorelease];
    annotationView.image = [UIImage imageNamed:@"circle.png"];
    annotationView.canShowCallout = YES;
}
else {
    annotationView.annotation = annotation;
}
    return annotationView;
}

调试器中的错误是:

Airports[3489:c07] -[MKMapView setAnnotations:]: 无法识别的选择器发送到实例 0x8095570 Airports[3489:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[MKMapView setAnnotations:]: unrecognized selector sent to instance 0x8095570” * 首先抛出调用栈: (0x1945012 0x1275e7e 0x19d04bd 0x1934bbc 0x193494e 0x2b6e 0x29e817 0x29e882 0x1eda25 0x1ee311 0x28db 0x1ba7b7 0x1bada7 0x1bbfab 0x1cd315 0x1ce24b 0x1bfcf8 0x18a0df9 0x18a0ad0 0x18babf5 0x18ba962 0x18ebbb6 0x18eaf44 0x18eae1b 0x1bb7da 0x1bd65c 0x282d 0x2765) libc++abi.dylib:终止调用抛出异常 共享库应用加载规则全部 当前语言:自动;目前客观-c

【问题讨论】:

  • 一开始,我尝试自己使用 ADClusterMapView,但最终受 WWDC 2011 演示文稿的启发,我构建了自己的简单集群系统。如果你想看看,请查看我的答案stackoverflow.com/a/20271466/1394534。 Google SDK 和 MapKit 都有代码
  • 比你!你有 github 上的示例项目或类似的东西吗?

标签: ios objective-c mkmapview mapkit mkannotationview


【解决方案1】:

[mapView setAnnotations:airports]; 似乎是问题所在。 从doc 开始,只有addAnnotations:addAnnotation: 及其删除等效项可用。另外,annotations 属性是readonly 所以setAnnotations 崩溃,正常

【讨论】:

    【解决方案2】:

    显然,这是因为您忘记更改 Identity Inspector 上的自定义类(右侧实用程序)。只需将值设置为 ADClusterMapView。

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 1970-01-01
      • 2023-03-08
      • 2013-09-20
      • 2020-10-09
      • 2012-09-19
      • 2015-09-14
      • 2017-08-20
      • 1970-01-01
      相关资源
      最近更新 更多