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 个这些我如何将它们放在一个数组中。

4

1 回答 1

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.

然后,您可以一次将注释添加到地图视图中:

[mapview addAnnotations:annotationArray];
于 2012-08-16T10:51:40.287 回答