【发布时间】:2012-04-06 23:34:27
【问题描述】:
我在地图视图上有一个注释。我可以以编程方式选择它,但我点击它没有任何反应。你可以帮帮我吗?有没有人遇到过类似的问题?这是设置注释的方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
if (!aView) {
aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
aView.canShowCallout = YES;
aView.draggable=YES;
aView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
// could put a rightCalloutAccessoryView here
}
aView.annotation = annotation;
[(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
return aView;
}
并将它们添加到地图视图中:
- (void)updateMapView
{
if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
if (self.annotation) [self.mapView addAnnotation:self.annotation];
}
以及对按下注释的反应方式:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView
{
NSLog(@"did select annotation");
}
顺便说一句,方法 [self.mapView selectAnnotation:annotation] 有效,但没有提出标注(我用断点检查了它)。虽然只是录制注释不会(再次检查断点)。
【问题讨论】:
-
您可能想要包含一些视图图像,或者提供一些代码来显示您的设置方式。如果没有更多细节,很难弄清楚发生了什么。
-
检查地图视图的代理是否已设置,并且注解的
title属性不是零或空白。 -
title 绝对不是 nil,我无法检查它是否为空。顺便提一下 - 拖动似乎也不起作用,忘了提到我没有标题作为属性,它只是我调用中的一种方法。希望这将被证明是有用的。
-
在 updateMapView 中,就在 addAnnotation 行之前,执行
NSLog(@"annotation title = {%@}", [annotation title]);。它说什么?还要从注释类中发布 title 方法的代码。此外,只有在注解类中有 setCoordinate 方法时,拖动才有效。 -
是的,原来是空白的。注释的标题是通过文本字段设置的,它是空白的,这就是原因。 Anna 也许您可以发布您的 anwser,以便将其标记为正确的?顺便说一句,我有一个单独的类来包装我的所有数据是否正确,我的注释类包含该数据类的实例?
标签: objective-c ios select annotations android-mapview