我想在userLocation的标题上添加点击操作。因此,我尝试添加rightCalloutAccessoryView,但希望保留默认标记。我怎么能这么做?
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]]){
MKAnnotationView *annotationView = //What need I put here?
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];
return annotationView;
}else {
return nil;
}
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"DetailsIphone" sender:view];
}发布于 2015-02-17 16:02:31
使用:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@" we selected annotation");
//self.mapView is your mapView ->
if(view.annotation == self.mapView.userLocation)
{
// do your action here like [self method]; in your case->
[self performSegueWithIdentifier:@"DetailsIphone" sender:view];
}
else {
//no userlocation annotation was tapped ...another code
}
}最新答复:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@" we selected annotation");
//self.mapView is your mapView ->
if(view.annotation == self.mapView.userLocation)
{
// do your action here like [self method]; in your case->
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
else {
//no userlocation annotation was tapped ...another code
}
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout was tapped");
[self performSegueWithIdentifier:@"DetailsIphone" sender:view];
}https://stackoverflow.com/questions/28565447
复制相似问题