[英]How to track which annotation callout clicked
I am creating an annotation callout with right accessory button, using the following code 我使用以下代码创建带有右侧附件按钮的注释标注
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]){
return nil;
}
else {
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
}
annotationView.image = [UIImage imageNamed:@"Mevents.png"];
annotationView.annotation = annotation;
annotationView.canShowCallout=YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
// UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
// pinView.leftCalloutAccessoryView = profileIconView;
// [profileIconView release];
return annotationView;
}
}
How can I track, which annotation is clicked ? 如何跟踪单击了哪个注释 ? I want to load the details screen with the id and fetch the data based on that id to show info.
我想用ID加载详细信息屏幕,并根据该ID获取数据以显示信息。
When you create the annotation add a tag to it 创建注释时,在其中添加标签
annotationView.image = [UIImage imageNamed:@"Mevents.png"];
//Add this after
annotationView.tag = 111;
Now in viewForAnnotation
, check for this tag 现在在
viewForAnnotation
,检查该标签
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]){
return nil;
if(annotation.tag == 111)
//Do something
else
//Do some other thing
}
hey bro check my answer in the following thread it can help you. 嘿兄弟在以下主题中检查我的答案,它可以为您提供帮助。
Pass data to detailView when annotation tapped on mapview 在mapview上点击注释时,将数据传递到detailView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.