gpt4 book ai didi

ios - 点击 userLocation 的标题

转载 作者:行者123 更新时间:2023-11-29 02:17:41 26 4
gpt4 key购买 nike

我想在点击 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];
}

最佳答案

使用:

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

关于ios - 点击 userLocation 的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28565447/

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