我想在 MKAnnotation 中添加更多详细信息,例如位置标题、描述、日期、位置名称。所以需要四行。但我发现只有 2 个参数可以传递给 MKAnnotation,即标题和副标题。如何在 map 上添加更多详细信息?请帮助我..提前致谢。
最佳答案
看看创建自定义 MKAnnotationView
对象...它基本上是一个为 map 注释量身定制的 UIView
。在该对象中,您可以拥有 4 个自定义标签。
在您的 MKMapViewDelegate
类中,您实现了 viewForAnnotation
方法:
- (CustomMapAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
CustomMapAnnotationView *annotationView = nil;
// determine the type of annotation, and produce the correct type of annotation view for it.
CustomMapAnnotation* myAnnotation = (CustomMapAnnotation *)annotation;
NSString* identifier = @"CustomMapAnnotation";
CustomMapAnnotationView *newAnnotationView = (CustomMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == newAnnotationView) {
newAnnotationView = [[[CustomMapAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}
annotationView = newAnnotationView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
这将在您有注释的地方显示您的自定义 View ...如果您想要一步一步的教程,check out this video .
希望对你有帮助
编辑
实际上我刚刚发现了一个新的 Maps example在 apple dev 站点上... 拥有您需要查看的所有源代码。他们还使用名为 WeatherAnnotationView
MKAnnotationView
关于iphone - 如何在 iOS 的 MKAnnotation 中添加更多细节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2342070/