我试图在MKMapViewDelegate中使用一些委托方法。具体来说,我想给弹出一个辅助箭头,以便当用户触摸它时,它会启动本机地图应用程序(对于完整的映射功能)。
我认为我正确地理解了,一旦将VC设置为自己的委托,协议方法就会被自动调用。在这种情况下,委托方法是否会被自动调用,或者您是否必须执行其他操作?
这是启动地图的方法。
-(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;
}我怎样才能让这个方法发射,然后得到辅助箭头呢?谢谢你的建议。
发布于 2015-05-11 11:35:28
当您单击注释视图中的按钮时,为什么不使用此方法?这个方法被触发,您可以在那里执行自定义操作。
- (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];
}
}
}https://stackoverflow.com/questions/30165958
复制相似问题