如何在 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.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要向地图添加注释,然后为其提供自定义视图。
要向地图添加注释,请在您的对象之一中采用 MKAnnotation 协议,并将其坐标属性设置为适当的纬度/经度位置。
接下来,您将使用 MKMapView addAnnotation 将注释添加到地图。
将地图的委托属性设置为您的视图控制器,然后实现 mapView:viewForAnnotation:
当调用此方法时,为您的注释返回 MKAnnotationView。将 MKAnnotationView 的 image 属性设置为您希望注释使用的任何图像(也许是按钮的图像?)。
如果您想知道注释何时被选择,您可以实现mapView:didSelectAnnotationView:。
您还可以使用 MKAnnotationView 的 leftCalloutAccessoryView 和 rightCalloutAccessoryView 属性在注释上设置标注附件按钮。如果您这样做,则可以在用户选择标注按钮时通过实现 mapView:annotationView:calloutAccessoryControlTapped: 进行响应。
You'll want to add an annotation to the map, then provide a custom view for it.
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.
Next, you'll add the annotation to the map using MKMapView addAnnotation.
Set the map's delegate property to your view controller, then implement mapView:viewForAnnotation:
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?).
You can implement mapView:didSelectAnnotationView: if you want to know when the annotation was selected.
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:.