如何在iOS中的MKAnnotation中添加更多的细节

我想在MKAnnotation中添加更多的细节,如位置标题,描述,date,位置名称。 所以这将是四条线所需要的。 但是我发现只有2个参数可以传递给标题和副标题的MKAnnotation。 如何在地图上添加更多细节? Plz帮助我..提前感谢。

看看创build一个自定义的MKAnnotationView对象…它基本上是一个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; } 

这将显示您的自定义视图,无论你有一个注释…如果你想一步一步的教程, 看看这个video 。

希望这可以帮助

编辑

我实际上刚刚在苹果开发网站上find了一个新的地图示例 …有所有您需要通过的源代码。 他们也使用一个名为WeatherAnnotationView的自定义WeatherAnnotationView