Bab*_*bul 22 iphone objective-c map mkmapview ios
我是Maps Concept的新手.
请找一次附图.

当我点击"pin"时,我收到消息说"欣赏你的笑容"或任何文字.....现在我想要...当我们选择表视图时,我需要为该引脚提出该消息(与该针的用户交互)...
我在下面的代码中使用了这个地图和引脚.
-(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;
}
Run Code Online (Sandbox Code Playgroud)
现在我将如下所示显示所有引脚.

怎么做当我们点击表视图时,我需要显示该引脚的标题,就像我们选择引脚时的显示方式一样?
提前致谢
ada*_*eks 30
您正在寻找的方法是selectAnnotation : .
在您的中didSelectRowAtIndexPath,您必须找到与表行关联的注释.
一旦找到它,你就可以告诉它,通过使用它来选择它:
[mapView selectAnnotation:foundAnnotation animated:YES];
Run Code Online (Sandbox Code Playgroud)
与目标 C 答案相同,在您的 tableview 中,您有一个注释列表。在 Swift 中didSelectRow:
对于 Swift 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)
Run Code Online (Sandbox Code Playgroud)
简短而简单。
| 归档时间: |
|
| 查看次数: |
10744 次 |
| 最近记录: |