为了在 Storyboard iOS 项目中创建地图注释,我使用了:
CLLocationCoordinate2D annotationCoord3;
annotationCoord3.latitude = 34.233129;
annotationCoord3.longitude = -118.998644;
MKPointAnnotation *annotationPoint3 = [[MKPointAnnotation alloc] init];
annotationPoint3.coordinate = annotationCoord3;
annotationPoint3.title = @"Another Spot";
annotationPoint3.subtitle = @"More than a Fluke";
[_mapView addAnnotation:annotationPoint3];
它工作得很好,但我想添加一个公开按钮,以便我可以将序列推送到新的视图控制器并显示图像。这可能吗?
提前谢谢,
--bd--
声明你的班级是MKMapViewDelegate
。然后加
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"String"];
if(!annotationView) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
return annotationView;
}
然后你添加:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// Go to edit view
ViewController *detailViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
... ViewController 可以是您定义的任何内容(我使用 nib 文件...)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)