0

我们正在尝试在 iOS 应用程序中实现 MKMapView。我得到了带有给定位置和引脚的 mapView。当我点击这些引脚时,我也得到了标题和副标题。现在我想在这个视图中包含一个详细信息披露按钮,其中显示标题和副标题。为此,我使用了下面给定的代码[MKPinannotation 详细信息披露按钮-当前新视图正在第一个方法中,但它没有显示 detailDisclosureButton。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
    if (!pinView) {
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease];
        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;

        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView = rightButton;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
}


- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped
{
}

现在我该怎么办?任何人请看看并帮助我......

4

2 回答 2

1
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {

    pinView = nil; 
    if(annotation != map.userLocation) 
    {
        NSString *defaultPinID =@"com.invasivecode.pin1";
        pinView = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
        UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [btnGo addTarget:self action:@selector(goToLocation:)  forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView=btnGo;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        pinView.draggable=NO;
    } 
    else {
        [map.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

在 .h 文件中声明

MKPinAnnotationView *pinView
于 2013-03-19T06:31:40.467 回答
0

请尝试为 rightButton 设置框架,即

rightButton.frame = CGRectMAke (x,y,width,height);
于 2013-03-19T06:26:23.100 回答