【发布时间】:2012-10-12 14:37:43
【问题描述】:
我想重新排列地图上显示的注释数组,以便创建一个下一个/上一个按钮,以便使用简单的迭代器快速循环浏览所有注释(按日期排序)。
据我所知,用作存储的 annotations 数组 [worldmap annotations] 是不可变的,因此我无法对其重新排序。我尝试了以下方法来创建注释数组的临时副本,按日期对其进行排序并重新附加它。
(世界地图是我的 MKMapView 对象)
//COPY
NSMutableArray *annotationSort = [[NSMutableArray alloc]initWithArray:[worldmap annotations]];
//SORT
[annotationSort sortedArrayUsingComparator:^NSComparisonResult(EventPin* obj1, EventPin* obj2) {
return [obj1.eventItemObject.eventDateBegin compare: obj2.eventItemObject.eventDateBegin];
}];
//ADDED SORTED ARRAY
[worldmap removeAnnotations:[worldmap annotations]];
[worldmap addAnnotations:annotationSort];
这似乎不起作用。知道如何重新排序 MKMapKit 注释数组吗?
【问题讨论】:
-
看看这个问题和答案:stackoverflow.com/questions/9539802/…
标签: objective-c annotations mkmapview mapkit