Search code examples
iphoneandroid-mapviewmkannotation

Help adding annotations to NSMutableArray


I'm trying to add annotations to NSMutableArray annToLoad so I can later perform [mapView addAnnotations:annToLoad];

It doesn't seem to be working, and when I log the array, I get a (null) value.

My code is below... thanks!!

// Loop Begins
DisplayMap *ann = [[DisplayMap alloc] init]; 
ann.title = [NSString stringWithFormat: @"Title"];  
ann.subtitle = [NSString stringWithFormat: @"SubTitle"];
ann.coordinate = coord;

[annToLoad addObject:ann];            
[ann release];
// Loop Ends

// Outside of Loop
[mapView addAnnotations:annToLoad];

Solution

  • You need to alloc init the NSMutableArray and assign it to the property. The property will retain what you set but you still need to alloc, init and assign.

    You can either do it in the init of that class or above the loop - depending on the lifetime of the array you need.