gpt4 book ai didi

IOS/ objective-c /MKMapViewDelegate : Get annotationView to show accessory arrow

转载 作者:行者123 更新时间:2023-11-28 19:49:24 25 4
gpt4 key购买 nike

我正在尝试在 MKMapViewDelegate 中使用一些委托(delegate)方法。具体来说,我想给弹出框一个附件箭头,这样当用户触摸它时,它会启动本地 map 应用程序(用于完整的 map 绘制功能。)

我想我的理解是正确的,一旦将 VC 设置为自身的委托(delegate),协议(protocol)方法就会自动调用。在这种情况下,委托(delegate)方法是自动调用还是您必须执行其他操作?

这是启动 map 的方法。

-(void) geoCodeAndMapIt {
NSString* location = @"156 University Ave, Palo Alto, CA 94301";
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]
initWithPlacemark:topResult];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(placemark.coordinate, 5000, 5000);//5000 is meters
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;

[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:placemark];
}

这是应该向标注添加附件箭头但未触发的方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

return annotationView;
}

如何触发此方法以便获得附件箭头?感谢您的任何建议。

最佳答案

当您在注释 View 中单击按钮时,为什么不使用此方法此方法会被触发,您可以在那里执行自定义操作。

 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
//Do whatever you want to do here.

PropertyLocation *location = (PropertyLocation*)view.annotation;

for(PropertyDTO *property in self.items)
{
if(property.location == location)
{
PropertyDetailVC *detailVC = [PropertyDetailVC propertyDetailVCWithNodeID:property.nodeID];

[self.navigationController pushViewController:detailVC animated:YES];
}
}

}

关于IOS/ objective-c /MKMapViewDelegate : Get annotationView to show accessory arrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30165958/

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