我不确定为什么详细信息披露按钮没有出现在mapkit标注上。这是我的代码:

我确保将其包含在.h文件中
然后是以下方法。该标注会起作用,并在地图加载后立即显示。我还确保将委托连接到Xib文件中。

   - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *mapPin = nil;
    if(annotation != map.userLocation)
    {
        static NSString *defaultPinID = @"defaultPin";
        mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (mapPin == nil )
        {
            mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
                                                     reuseIdentifier:defaultPinID];
            mapPin.canShowCallout = YES;

            UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [disclosureButton addTarget:self action:@selector(clDetails:) forControlEvents:UIControlEventTouchUpInside];

            mapPin.rightCalloutAccessoryView = disclosureButton;

        }
        else
            mapPin.annotation = annotation;

    }
    return mapPin;
}




  - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    id<MKAnnotation> myAnnotation = [self.mapView.annotations objectAtIndex:0];
    [self.mapView selectAnnotation:myAnnotation animated:YES];
}

谢谢你的帮助。

最佳答案

我在viewDidLoad中有这行代码,这是MKAnnotation方法引发的。

mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];

:)

关于objective-c - 详细信息披露按钮未出现在mapkit标注上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12247141/

10-11 22:27