所以我在我的应用程序的地图上有 MKAnnotationViews,但是,我似乎无法让注释显示标注。这是我尝试过的一些代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"Bar";
if ([annotation isKindOfClass:[BarLocations class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.animatesDrop = YES;
//Doesn't work
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame = CGRectMake(0, 0, 23, 23);
annotationView.rightCalloutAccessoryView = button;
//Doesn't work
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[annotationView setLeftCalloutAccessoryView:leftButton];
annotationView.canShowCallout = YES;
//Doesn't work
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
rightButton.frame = CGRectMake(0, 0, 15, 15);
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
注意 - 我分别尝试了其中的每一个 - 我只是在这篇文章中将它们放在一起以显示我已经尝试过的选项。
我究竟做错了什么?
编辑
我想我发现了问题的很大一部分:永远不会调用以下方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
但是,我认为MkMapView
's are like UITableView
's。那我怎么称呼它。我忘了指派代表吗?
任何帮助,将不胜感激