我有一個NSMutableArray,它擁有一個MKMapkit的Custom類。如何修改特定數組中的NSMutableArray
MapPoint *placeObject = [[MapPoint alloc] initWithTitle:title subtitle:subtitle coordinate:loc description:description storeImage:storeImage];
[annotationArray addObject:placeObject];
我的日常充滿placeObject
沒有圖像,因爲他們將異步加載和幾秒鐘後完成。現在我的問題是:有沒有辦法改變annotationArray
內的placeObject
?
編輯
爲了在這裏更好的方式顯示我的問題有些部分代碼:
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];
}
}
只要改變它。它是存儲在數組中的指針,不是placeObject的副本。無論你對原始數據做什麼「將出現」在通過數組訪問的版本中(因爲它們將是同一個對象)。 – 2013-05-02 17:00:39