我正在使用右侧附件按钮创建注释标注,使用以下代码
- (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;
}
}
如何跟踪,点击哪个注释?我想使用 id 加载详细信息屏幕,并根据该ID获取数据以显示信息。
答案 0 :(得分:0)
创建注释时,为其添加标记
annotationView.image = [UIImage imageNamed:@"Mevents.png"];
//Add this after
annotationView.tag = 111;
现在在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
}
答案 1 :(得分:0)