gpt4 book ai didi

objective-c - NSSet 到 NSArray 转换调用 objectAtIndex?

转载 作者:IT老高 更新时间:2023-10-28 11:39:34 26 4
gpt4 key购买 nike

我正在尝试通过删除可见区域外的所有注释以及在可见区域内添加和删除一些注释来更新 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 然后添加注释的最后一行之后。有没有关于将数组转换为导致这种情况的集合?如果是这样,有没有办法解决它?

最佳答案

尽管您将 NSMutableSet 转换为 NSArray,但简单的转换不会使 NSSet 类响应 NSArray的消息。您必须使用 NSSet 的元素填充实际的 NSArray,如下所示:

NSArray *array = [theNsSet allObjects];

关于objective-c - NSSet 到 NSArray 转换调用 objectAtIndex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8985053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com