2011-05-26 116 views
5

是否有一种方法(或任何方式),就可以得到该方法中注释的“索引路径”:MapView注解indexPath?

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation

我想要做的就是根据注释得到一个数组里面的东西。我认为我想要复制的一种方法是- tableView:cellForRowAtIndexPath:并使用“indexPath”。

搜索了很多,但没有找到任何结果。或者,也许我只是在寻找不好。任何参考将不胜感激。

+0

如果你只是想要一个注释数组,不能使用'mapView.annotations'来给出一个注释数组。 – visakh7 2011-05-26 10:01:34

+0

我需要获取注释之外的数据(来自不同的数据集),所以只是注释不起作用。 – Angelo 2011-05-27 03:15:28

回答

-1

要回答我的问题(这本是如何为我的作品):

我创造了自定义注解实例和传输的数据有,那里面- mapView:viewForAnnotation:(我使用的自定义pinView)我进口创造了一个我的CustomAnnotation实例并从那里获取数据。

[customAnnotation setSomething: data];
- mapView:viewForAnnotation: 
{ 
    pinView = [[[CustomPinView alloc] initWithAnnotation: annotation reuseIdentifier: PinIdentifier] autorelease]; 
}
- initWithAnnotation:reuseIdentifier: 
{ 
  CustomAnnotation *customAnnotation = (CustomAnnotation *)annotation; 

    [customAnnotation something]; 
}

矫枉过正我,但它能够完成任务。

4
NSUInteger index = [mapView.annotations indexOfObject:annotation]; 

由于底层数组是可变的,请注意index可以更改。这似乎是最接近的indexPath像你可以得到的信息。

+0

是的,但如前所述,索引正在改变,它不会工作(或大多不会工作)。有时候,它会从不同的索引获取信息。另一件事是,如果用户位置是打开的,你应该将注释转移到一个NSMutableArray并且首先删除它(索引:0)。 – Angelo 2011-05-27 02:55:49