我正在尝试通过删除可见区域外的所有注释以及在可见区域内添加和删除一些注释来更新 MKMapView。这是我的代码:
NSSet *visibleAnnotations = [mapView annotationsInMapRect:[mapView visibleMapRect]];
NSSet *allAnnotations = [NSSet setWithArray:[mapView annotations]];
NSMutableSet *nonVisibleAnnotations = [NSMutableSet setWithSet:allAnnotations];
[nonVisibleAnnotations minusSet:visibleAnnotations];
[mapView removeAnnotations:(NSArray *)nonVisibleAnnotations];
NSMutableSet *newAnnotations = [NSMutableSet setWithArray:[_zoomLevels objectAtIndex:clusterLevel]];
[newAnnotations minusSet:visibleAnnotations];
[mapView addAnnotations:(NSArray *)newAnnotations];
这给了我错误-[__NSCFSet objectAtIndex:]: unrecognized selector sent to instance 0x13cd40在我将 newAnnotations 转换为 NSArray 然后添加注释的最后一行之后。有没有关于将数组转换为导致这种情况的集合?如果是这样,有没有办法绕过它?