【发布时间】:2016-01-12 08:43:15
【问题描述】:
【问题讨论】:
-
表示你想为每个注释分配唯一的标签?
-
在向 MapView 添加注释的地方添加代码 sn-p。
-
我不想分配。如果用户单击注释,我已经显示注释需要获取索引值。
标签: objective-c iphone methods mkmapview mkmapviewdelegate
【问题讨论】:
标签: objective-c iphone methods mkmapview mkmapviewdelegate
找到一个答案,这将返回注释点击的数字:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
NSUInteger index = [mapView.annotations indexOfObject:view.annotation];
NSLog(@"index no %d",index);
}
上面的代码会在我们每次点击注解时生成随机索引号。
但需要重写代码如下
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
// Annotation is your custom class that holds information about the annotation
if ([view.annotation isKindOfClass:[Annotation class]]) {
Annotation *annot = view.annotation;
NSInteger index = [self.arrayOfAnnotations indexOfObject:annot];
}
}
【讨论】: