我应该使用MKAnnotation,MKAnnotationView或MKPinAnnotation? [英] Should I use MKAnnotation, MKAnnotationView or MKPinAnnotation?

查看:331
本文介绍了我应该使用MKAnnotation,MKAnnotationView或MKPinAnnotation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话web服务和一个图形页面绘制某些对象。

I'm calling a webservice and plotting some objects on a MapView.

什么我不能明白的是我应该用MKAnnotationPoint或MkAnnotationView?我不确定。当我使用MKAnnotation,引脚显示在地图上,如果我点击他们,他们给我的标题和字幕。

What I'm failing to understand is should I use MKAnnotationPoint or MkAnnotationView? I'm not sure. When I use MKAnnotation, the pins show up on the map, if I click on them, they show me the title, and subtitle.

如果我用MKAnnotationView,引脚显示出来,但是当我点击它们,什么都不会发生。

If I use MKAnnotationView, the pins show up but when I click on them, nothing happens.

我也尝试添加右键标注/雪佛龙公司在寻找按钮,但一直没能图说出来无论是。

I'm also trying to add the right button callout/chevron looking button but haven't been able to figure that out either.

下面是我的代码的例子。

Here's an example of my code.

    MKPointAnnotation mk = new MKPointAnnotation();
MKAnnotationView mkView = new MKAnnotationView();
mk.Coordinate = coord;
mk.Title = tl.Name;
mk.Subtitle = DateTime.Now.ToShortDateString();
mkView.Annotation = mk;             
mapView.AddAnnotationObject(mkView);



所以,如果我做以上 - 引脚露面,但我不能点击任何的。他们

So if I do the above - the pins show up, but I can't click on any of them.

如果我只用:

mapView.AddAnotationObject(mk); //not using the MkAnnotationView



然后,他们都出现了,可点击。我不知道如何将rightcalloutbutton添加到他们尚未虽然。所以这还挺第二部分的问题。

Then they all show up and are clickable. I'm not sure how to add the rightcalloutbutton to them yet though. So that's kinda a second part to the question.

感谢。

推荐答案

我没有使用MonoTouch的,但底层SDK使用相同的iOS我相信。

I haven't used MonoTouch but the underlying SDK usage is the same as iOS I believe.

MKAnnotation 是协议/接口基于您的注释数据模型。你也可以使用预先定义的 MKPointAnnotation 类(它实现 MKAnnotation 接口)为你的注释数据模型对象,而不是创建一个自定义类,如果你需要的是标题字幕协调<中/ code>。

MKAnnotation is the protocol/interface to base your annotation data model on. You could also use the pre-defined MKPointAnnotation class (which implements the MKAnnotation interface) for your annotation data model objects instead of creating a custom class if all you need is title, subtitle, and coordinate.

MKAnnotationView 是标注的观点应该出现在设置地图视图的 viewForAnnotation 的委托方法(而不是创建内联)。将具有相同的外观(例如,销图像)的多个注释对象之间注解视图可以被重新使用。所以理论上一个 MKAnnotationView 实例可以被用于实施 MKAnnotation (假设多个注释对象,他们是不是所有的屏幕一次)。

MKAnnotationView is how the annotation's view should appear and is set in the map view's viewForAnnotation delegate method (not created inline). Annotation views can be re-used between multiple annotation objects that will have the same appearance (for example a pin image). So theoretically a single MKAnnotationView instance might be used for multiple annotation objects that implement MKAnnotation (assuming they are not all on the screen at once).

所以,你创建一个 MKAnnotation 基于对象和传递,在 addAnnotation (即 AddAnnotationObject )的调用。然后在 viewForAnnotation 委托方法,创建并返回一个 MKAnnotationView 基于对象的实例。

So you create an MKAnnotation-based object and pass that in the addAnnotation (ie. AddAnnotationObject) call. Then in the viewForAnnotation delegate method, you create and return an instance of an MKAnnotationView-based object.

MKPinAnnotation(实际上 MKPinAnnotationView )是一个预先定义的子类 MKAnnotationView 它提供了一个默认引脚的形象。你可以返回 MKPinAnnotationView viewForAnnotation 委托方法,而不是设计一个自定义视图。

"MKPinAnnotation" (actually MKPinAnnotationView) is a pre-defined subclass of MKAnnotationView which provides a default pin image. You can return an instance of MKPinAnnotationView in the viewForAnnotation delegate method instead of designing a custom view.

在这里您将创建正确标注附件按钮的地方是在 viewForAnnotation 委托方法。您创建一个的UIButton 类型 UIButtonTypeDetailDisclosure 并将其设置为注释视图的 rightCalloutAccessoryView

The place where you would create the right callout accessory button is in the viewForAnnotation delegate method. You create a UIButton of type UIButtonTypeDetailDisclosure and set it as the annotation view's rightCalloutAccessoryView.

按下按钮将在地图视图中的 calloutAccessoryControlTapped 委托方法来处理它提供了一个参考于注释视图和注释标注为。

The button press would be handled in the map view's calloutAccessoryControlTapped delegate method which provides a reference to the annotation view and annotation the callout is in.

给出的方法名是iOS中的那些,但MonoTouch的名字应该是相似的。

The method names given are the ones in iOS but the names in MonoTouch should be similar.

这篇关于我应该使用MKAnnotation,MKAnnotationView或MKPinAnnotation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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