gpt4 book ai didi

ios - 将披露按钮添加到 MKPointAnnotation

转载 作者:可可西里 更新时间:2023-11-01 04:21:37 29 4
gpt4 key购买 nike

为了在 Storyboard iOS 项目中创建 map 注释,我使用了:

    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];

效果很好,但我想添加一个披露按钮,这样我就可以将序列推送到新的 View Controller 并显示图像。这可能吗?

提前致谢,

--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 文件...)

关于ios - 将披露按钮添加到 MKPointAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10938517/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com