25

我是地图概念的新手。

请找到所附图像一次。

在此处输入图像描述

当我单击“图钉”时,我收到消息说“欣赏你的微笑”或任何文字.....现在我想要...当我们选择表格视图时,我需要为该图钉提出该消息(使用退出该引脚的用户交互)...

我正在使用下面的代码来制作这张地图和别针。

    -(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
customLocation.latitude=[casesobjc.latitude_string doubleValue];
        customLocation.longitude=[casesobjc.longitude_string doubleValue];
 MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:casesobjc.locationForMap_string andCoordinate:customLocation];
[mapView addAnnotation:newAnnotation];
}
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
 MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"annotation_ID"];
if (pin == nil) {
        pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"annotation_ID"];
    } else {
        pin.annotation = annotation;
    }
    pin.pinColor = MKPinAnnotationColorPurple;
    pin.animatesDrop = YES;
    pin.canShowCallout=YES;
return pin;
}

现在我将显示所有的引脚,如下所示。

在此处输入图像描述

怎么做当我们单击表格视图时,我需要显示该引脚的标题,就像我们选择引脚时的显示方式一样?

提前致谢

4

2 回答 2

32

您正在寻找的方法是selectAnnotation:

在您的didSelectRowAtIndexPath中,您必须找到与表格行关联的注释。

找到它后,您可以告诉它,使用以下命令选择它:

[mapView selectAnnotation:foundAnnotation animated:YES];
于 2013-04-02T19:52:54.000 回答
6

与 Objective C 的答案相同,在您的表格视图中,您有一个注释列表。在 Swift 中didSelectRow

对于斯威夫特 4:

// annotations would be the array of annotations - change to your required data sets name
let selectedAnnotation = annotations[indexPath.row]
self.mapView.selectAnnotation(selectedAnnotation, animated: true)

简短而简单。

于 2018-02-22T11:37:21.023 回答