2013-11-28 23 views
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]; 
} 
+0

的addAnnotations(複數)方​​法應該是所謂_after_數組完全填充(在循環之後)。是buddyDataArray正確添加對象還是顯示爲零(因爲alloc + init沒有完成)? – Anna

+0

是數組添加對象...並且我沒有在viewDidLoad中分配init。 – icodes

回答

0

您可以試試這種方法...確保您的presenceArray字典正在被儲存。

-(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.mapview addAnnotation:annotation]; 
    } 
} 

因爲你已經比循環你不需要創建註釋對象的數組。您可以直接添加到地圖正如我在上面的代碼做了..

+0

好的......會這麼做... thanx .... – icodes

相關問題