如何将Action选择器添加到Annotation视图上的弹出气泡中

时间:2013-08-19 06:57:13

标签: iphone objective-c annotations mkmapview mapkit

我对MapKit实施非常新的

在我的应用程序中,一页是地图视图

因为我已经显示了大量的引脚及其注释动作。

我在 popup bubble 上添加了一个Discloser按钮,并为这些披露按钮设置了操作,如下所示。

i Want to Same action When tap on that gray bubble

//To add a discloser button to show route map
        UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=detailBtn;
        [detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
        DisplayMap *ann=(DisplayMap *)annotation;
        detailBtn.tag = ann.detailButtonTag;



//viewForAnnotation DELEGATE for annotions
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = nil;
    if(annotation != mapView.userLocation)
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;

        //To add a discloser button to show route map
        UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=detailBtn;
        [detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
        DisplayMap *ann=(DisplayMap *)annotation;
        detailBtn.tag = ann.detailButtonTag;
    }
    else
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

但我想要同样的动作当点击那个灰色泡泡时......

如何做enter image description here

2 个答案:

答案 0 :(得分:0)

您必须使用以下委托方法来点击气泡。

    -(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(id<GMSMarker>)marker 
   {
    DetailViewController *Detail = [[DetailViewController alloc]initWithNibName:@" DetailViewController" bundle:nil];    
    Detail.data=marker.userData;  // passing the data    
    [self.navigationController pushViewController:restDetail animated:YES];  
   }

答案 1 :(得分:0)

MKMapViewDelegate中有两种方法:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

有关如何使用这些方法的更多详细信息,您可以通过Rob查看Answer

更新:

为此你可以使用Custom Callout。您可以使用&#34; showRoute&#34;创建自定义按钮。方法并添加为自定义标注内容视图的子视图。