首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >点击userLocation标题

点击userLocation标题
EN

Stack Overflow用户
提问于 2015-02-17 15:51:10
回答 1查看 115关注 0票数 0

我想在userLocation的标题上添加点击操作。因此,我尝试添加rightCalloutAccessoryView,但希望保留默认标记。我怎么能这么做?

代码语言:javascript
复制
- (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];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-17 16:02:31

使用:

代码语言:javascript
复制
   - (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  
     }
  }

最新答复:

代码语言:javascript
复制
   - (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];
 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28565447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档