不在带注释的视图中显示DetailDisclosureButton

时间:2013-03-19 06:21:44

标签: objective-c ios5 xcode4.3 mkmapviewdelegate

我们正在尝试在iOS应用程序中实现MKMapView。我得到了带有给定位置和引脚的mapView。当我点击这些引脚时,我也得到了标题和副标题。现在我想在此包含一个详细的Disclosure按钮显示标题和副标题的视图。为此,我使用了下面给出的代码[MKPinannotation detail disclosure按钮 - 显示新视图进入第一个方法,但它没有显示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
{
}

现在我能做什么?有人请看看并帮助我......

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

请尝试设置rightButton的框架,即

rightButton.frame = CGRectMAke (x,y,width,height);