0

I have a NSMutableArray which holds a Custom class of MKMapkit.

MapPoint *placeObject = [[MapPoint alloc] initWithTitle:title subtitle:subtitle coordinate:loc description:description storeImage:storeImage];
[annotationArray addObject:placeObject];

My routine fills the placeObject without the image because they will load asynchronously and finished after a couple of seconds. Now my questions is: Is there a way to alter the placeObject which is within the annotationArray?

EDIT

To display my issue in a better way here some code parts:

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];

after this is done: dispatch_queue_t will start working. So I check every 2 seconds if its fully loaded. Then I start to alter annotationArray and refresh my annotations (remove all -> add to map which additional image)

- (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];
    }
}
1
  • Just alter it. It's a pointer stored in the array, not a copy of the placeObject. Whatever you do to the original will "appear" in the version accessed through the array (since they will be the same object). Commented May 2, 2013 at 17:00

3 Answers 3

4

All you need to do is get a reference to one of the MapPoint objects in the array. Then you can set properties and/or call methods on the object as needed.

MapPoint *point = annotationArray[x]; // x is whatever index you need
point.image = ... // some image
Sign up to request clarification or add additional context in comments.

6 Comments

Are you sure that annotationArray isn't nil?
I updatet my question annotationArray isn't nil, only the space for the Image
Did you use @synthesize and/or explicitly create your own ivar for the annotationArray property? It's possible the backing ivar is really _annotationArray. If you have a property then use it. Change everything to self.annotationArray to be sure.
self. effect nothing and annotationArray is synthesized
I found the issue: imageArray is nil in checkMap but why?
|
0

You can retrieve from your mutable array, the object you want to alter with the objectAtIndex method

NSInteger indexofMyObject = 0;
MapPoint *point = [myArray objectAtIndex:indexofMyObject];

Comments

0

Your MapPoint instance placeObject is a pointer. So adding it to the array does not copy placeObject by value, but actually holds its address. Getting the address of the object from the array will allow you to manipulate it.

annotationArray[objectIndex].anything = anything you want

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.