如何在iOS中的MKAnnotation中添加更多细节 [英] How to add more details in MKAnnotation in iOS

查看:108
本文介绍了如何在iOS中的MKAnnotation中添加更多细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to add more details in MKAnnotation like location title, description, date, location name. So it will be four lines that are needed. But I found that only 2 parameters can be passed to MKAnnotation which are title and subtitle. How can I add more details on the map? Plz help me..Thanks in advance.

推荐答案

看看创建自定义 MKAnnotationView object ...它基本上是为地图注释量身定制的 UIView 。在该对象中,您可以拥有4个自定义标签。

Take a look at creating a custom MKAnnotationView object... it is basically a UIView that is tailored for map annotations. In that object you could have your 4 custom labels.

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;
}

这将显示您的自定义视图,只要您有注释...如果你想要一步一步的教程,查看此视频

And that will display your custom view where ever you have an annotation... if you want a step by step tutorial, check out this video.

希望这会有所帮助

EDIT

我实际上刚刚发现了一个新的地图示例包含您需要完成的所有源代码。他们还使用自定义 MKAnnotationView 名为 WeatherAnnotationView

I actually just found a new Maps example on the apple dev site... has all the source code you need to go through. They are also using a custom MKAnnotationView called WeatherAnnotationView

这篇关于如何在iOS中的MKAnnotation中添加更多细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆