我不确定为什么详细信息披露按钮没有出现在 Mapkit 标注上。这是我的代码:
我确保包含在 .h 文件中 然后是下面的方法。标注有效并在 map 加载后立即显示。我还确保在 Xib 文件中连接委托(delegate)。
- (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/