Ily*_*pan 1 select annotations objective-c ios android-mapview
我在地图视图上有一个注释.我可以通过编程方式选择它,但我点击它没有任何反应.你可以帮帮我吗?有没有人遇到类似的问题?这是设置anotations的方法:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
并将它们添加到地图视图中:
- (void)updateMapView
{
if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
if (self.annotation) [self.mapView addAnnotation:self.annotation];
}
Run Code Online (Sandbox Code Playgroud)
并且对按下注释做出反应:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView
{
NSLog(@"did select annotation");
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,方法[self.mapView selectAnnotation:annotation]有效,但没有提出一个标注(我用断点检查它).虽然只是录制注释不会(再次通过断点).
小智 7
如果注释title为nil或空白,则不会显示标注(即使其他所有内容都已正确设置,包括canShowCallout).
当您点击注释时,didSelectAnnotationView将调用委托方法,如果注释具有非空白title,则将显示标注.
关于你在评论中提出的问题:
...是不是我有一个单独的类来包装我的所有数据,我的注释类包含该数据类的实例?
这没什么不对.
如果你想将与地图相关的逻辑与基类分开,那很好,对于复杂的应用程序来说可能是一个好主意,其中基础数据类可能不仅仅用于注释.
如果您的应用程序非常简单并且数据仅用于注释,那么您可以保持简单并将两者结合起来,但这不是必需的.
只要您坚持使用直接引用而不是尝试,例如,使用数组索引或视图/按钮标记链接回注释中的某些数据对象,"正确"类实现取决于适用于您的应用程序的内容.
| 归档时间: |
|
| 查看次数: |
4890 次 |
| 最近记录: |