2010-02-26 69 views
20

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

+3

我试图通过添加到副标题的细节..但它显示在一行..我如何能显示多行细节 – 2010-02-26 13:59:53

回答

15

看看创建自定义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; 
} 

这将显示在以往任何时候,如果你想一步步的教程,check out this video你有一个注释...您的自定义视图。

希望这有助于

编辑

我其实只是找到了一个新Maps example在苹果开发站点...有你需要去通过所有的源代码。他们也使用自定义MKAnnotationViewWeatherAnnotationView

+0

谢谢你的答案。我是否可以将细节添加到想要的格式的默认气泡中,如使用换行符?我尝试通过将UIlabel添加到MKPinAnnotationView的rightCalloutAccessoryView。但它不提供nice.thanks提前 – 2010-02-26 22:27:38

+0

我不会尝试这样做你试图做到这一点...苹果已设置注释,以便他们可以扩展与MKAnnotationView类。试图以你正在做的方式覆盖正确的CalloutAccessoryView并不是一个好的方法来做到这一点......你正在与框架战斗,它给你带来了奇怪的结果。如果您想要自定义注释,最好的方式就是我描述的方式。 – 2010-02-27 16:15:18

+0

查看我的新编辑了解更多信息 – 2010-02-28 06:01:39

相关问题