我正在尝试通过移除可视区域外的所有注释并添加和删除可视区域内的某些注释来更新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];
在将newAnnotations强制转换为NSArray后添加注释,最后一行会出现错误-[__NSCFSet objectAtIndex:]: unrecognized selector sent to instance 0x13cd40。是否将数组强制转换为集合会导致此错误?如果是,有没有解决方法?
[theNSSet allObjects]
简单地将 NSSet 作为一个对象添加到 NSArray 中,这是失败的,因为我不需要一个包含 NSSet 的 NSArray,我需要从 NSSet 的内容中得到一个 NSArray。 - Logicsaurus Rex