iOS - 在 MKAnnotationView 上设置详细信息披露按钮
我的 MapViewController 中有以下方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
annotationView.canShowCallout = YES;
annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// could put a rightCalloutAccessoryView here
} else {
annotationView.annotation = annotation;
[(UIImageView *)annotationView.leftCalloutAccessoryView setImage:nil];
}
return annotationView;
}
我相信它已正确设置,但是当我的地图正确显示带有标题和副标题的注释,但它们不显示详细信息披露按钮时,我是否遗漏了某些内容?
另一件事是,在调试时永远不会调用此方法,但注释视图会显示标题和副标题。
I have the following method in my MapViewController:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
annotationView.canShowCallout = YES;
annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// could put a rightCalloutAccessoryView here
} else {
annotationView.annotation = annotation;
[(UIImageView *)annotationView.leftCalloutAccessoryView setImage:nil];
}
return annotationView;
}
I believe it's properly set up, but when my map shows my annotations with title and subtitle properly, but they don't show the detail disclosure button, am I missing something?
Another thing is that when debugging this method is never called, yet the annotation view shows up with title and subtitle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很可能未设置地图视图的
delegate
。如果未设置
delegate
或未实现viewForAnnotation
方法,地图视图将创建一个默认注释视图,该视图是一个红色图钉,其标注仅包含标题和副标题(除非标题为空,在这种情况下您将得到一个图钉,但没有标注)。将地图视图的
delegate
出口连接到文件的所有者,或者在代码中添加此内容(例如,在添加注释之前在viewDidLoad
中):此外,如果您不使用 ARC ,将
autorelease
添加到alloc
行以避免内存泄漏。Most likely the map view's
delegate
is not set.If the
delegate
is not set or if you don't implement theviewForAnnotation
method, the map view will create a default annotation view which is a red pin with a callout containing only the title and subtitle (unless the title is blank in which case you will get a pin but no callout).Either connect the map view's
delegate
outlet to File's Owner or in code add this (eg. inviewDidLoad
before the annotation is added):Also, if you're not using ARC, add
autorelease
to thealloc
lines to avoid a memory leak.