2012-08-16 68 views
0

我如何在Xcode的mapview中創建註解數組?我試過 NSMutableArray * ann = [NSMutableArray alloc] init];地圖註釋數組

註釋

CLLocationcoordinate2D thecoordinate; 
thecoordinate.latitude =92.3; 
thecoordinate.longitude = 12.78; 
MyAnnotationClass *ann = [MyAnnotationClass alloc]; 
region.coordinate = thecoordinate; 
[mapview addannotation: ann]; 

我的這些我如何把它們放在一個數組57。

回答

2

將消息addObject發送到NSMutableArray。

NSMutableArray* annotationArray = [[NSMutableArray alloc] init]; 
[annotationArray addObject:ann]; //ann is an instance of MyAnnotationClass. Call this method for every MyAnnotationClass object you have. 

另一種選擇是初始化與對象數組:

NSMutableArray* annotationArray =[NSMutableArray arrayWithObjects: arr1, arr2, arr3, arr4, nil]; //arr1,arr2... are your MyAnnotationClass objects. 

然後,您可以anotations添加到的MapView一下子:

[mapview addAnnotations:annotationArray]; 
+0

我可以在表中實現它查看標題以填充表格? – 2012-08-16 11:00:39

+0

@JamesFrempong你可以在任何你想要的地方實現它。實際上tableViews通常從NSArray或NSMutableArray填充。 – 2012-08-16 11:03:29