如何在iPhone中的地图上放置按钮 [英] How to put a button on a Map in Iphone

查看:98
本文介绍了如何在iPhone中的地图上放置按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MKMapView在与接口构建器的应用程序中提取地图,但由于某种原因其未显示.我也想通过单击该视图来向该视图中添加一些按钮,以浏览iphone中现有的文件.

i am trying to pull a map in my applcation with interface builder using MKMapView but for some reason its not showing up. Also i want to add some button to this view by clicking which i can browse a file existing in my iphone.

请为我提供详细说明,因为我是新手.

Please provide me with the detial description as i am new to this.

谢谢

推荐答案

您需要向地图添加注释,然后为其提供自定义视图.

You'll want to add an annotation to the map, then provide a custom view for it.

要向地图添加注释,请在您的一个对象中采用 MKAnnotation 协议,并将其 coordinate 属性设置为适当的经/纬度位置.

To add an annotation to the map, adopt the MKAnnotation protocol in one of your objects and set its coordinate property to the appropriate lat/lon location.

接下来,您将使用 MKMapView addAnnotation 将注释添加到地图.

Next, you'll add the annotation to the map using MKMapView addAnnotation.

将地图的委托属性设置为您的视图控制器,然后实现 mapView:viewForAnnotation:

Set the map's delegate property to your view controller, then implement mapView:viewForAnnotation:

调用此方法时,为您的注释返回MKAnnotationView.将MKAnnotationView的 image 属性设置为您要注释使用的任何图像(也许是按钮的图像?).

When this method gets called, return a MKAnnotationView for your annotation. Set the MKAnnotationView's image property to whatever image you want the annotation to use (an image of a button perhaps?).

如果想知道何时选择注释,则可以实现 mapView:didSelectAnnotationView:.

You can implement mapView:didSelectAnnotationView: if you want to know when the annotation was selected.

您还可以使用MKAnnotationView的 leftCalloutAccessoryView rightCalloutAccessoryView 属性在注释上设置标注附件按钮.如果这样做,则可以通过实现 mapView:annotationView:calloutAccessoryControlTapped:来响应用户选择标注按钮的情况.

You can also set a callout accessory button on the annotation using MKAnnotationView's leftCalloutAccessoryView and rightCalloutAccessoryView properties. If you do this, you can then respond when the user selects the callout button by implementing mapView:annotationView:calloutAccessoryControlTapped:.

这篇关于如何在iPhone中的地图上放置按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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