0
我一直在嘗試做一段時間,但仍然無法顯示多個註釋。 這裏是我如何AppDelegate
如何在iOS中設置多個註釋字典
// set the values to mutable dictionary
[_locationDictionary setObject:latitudeObj forKey:@"latitudeValue"];
[_locationDictionary setObject:longitudeObj forKey:@"longitudeValue"];
[_locationDictionary setObject:fromUser forKey:@"fromUser"];
// add to array
[_presenceArray addObject:_locationDictionary];
將數據存儲到NSMutableDictionary
然後NSMutableArray
而這個我另一個視圖控制器裏面做的事情。
-(void)getPresenceData {
for(NSDictionary *dictObj in appDelegate.presenceArray) // this array that has dictionaries
{
annotation = [[Annotation alloc]init]; // Annotation Class
annotation.coordinate = CLLocationCoordinate2DMake([[dictObj valueForKey:@"latitudeValue"]doubleValue], [[dictObj valueForKey:@"longitudeValue"]doubleValue]);
annotation.title = [dictObj objectForKey:@"fromUser"];
[self.buddyDataArray addObject:annotation];
NSLog(@"buddy data array is %@", self.buddyDataArray);
[self.mapView addAnnotations:buddyDataArray];
}
的addAnnotations(複數)方法應該是所謂_after_數組完全填充(在循環之後)。是buddyDataArray正確添加對象還是顯示爲零(因爲alloc + init沒有完成)? – Anna
是數組添加對象...並且我沒有在viewDidLoad中分配init。 – icodes