我试图通过删除可见区域之外的所有注释,并在可见区域内添加和删除一些注释来更新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,在最后一行中,我将新注释投射到NSArray,然后添加注释.将一个数组投射到一个集合中会导致这种情况吗?如果是这样的话,有办法解决吗?