我有一个 NSMutableArray,它拥有一个自定义类的 MKMapkit。
MapPoint *placeObject = [[MapPoint alloc] initWithTitle:title subtitle:subtitle coordinate:loc description:description storeImage:storeImage];
[annotationArray addObject:placeObject];
我的例程填充placeObject
没有图像,因为它们将异步加载并在几秒钟后完成。placeObject
现在我的问题是:有没有办法改变annotationArray
?
编辑
为了更好地显示我的问题,这里有一些代码部分:
if (annotationArray == nil)
{
[self setAnnotationArray:[[NSMutableArray alloc] init]];
}
for (NSDictionary *locationDetails in parser.items)
{
__block NSData *storeImageData;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(queue, ^{
storeImageData = [NSData dataWithContentsOfURL:storeImageURL];
dispatch_sync(dispatch_get_main_queue(), ^{
UIImage *storeImageTMP = [UIImage imageWithData:storeImageData];
counterBlock ++;
NSLog(@"async: %d", counterBlock);
[imageArray addObject:storeImageTMP];
});
});
MapPoint *placeObject = [[MapPoint alloc] initWithTitle:title subtitle:subtitle coordinate:loc description:description storeImage:storeImage];
[annotationArray addObject:placeObject];
}
[mapView addAnnotations:annotationArray];
完成后:dispatch_queue_t
将开始工作。因此,我每 2 秒检查一次是否已满载。然后我开始更改 annotationArray 并刷新我的注释(删除所有 -> 添加到地图女巫附加图像)
- (void) checkMap
{
if (counterBlock == 547)
{
for (int i=0; i<=counterBlock; i++)
{
MapPoint *point = annotationArray[i];
point.storeImage = imageArray[i];
}
if(timer)
{
[timer invalidate];
timer = nil;
}
[mapView removeAnnotations:mapView.annotations];
[mapView addAnnotations:annotationArray];
}
}