如何在表格视图中设置注释的距离? [英] How do I set distance to annotation in tableview?

查看:126
本文介绍了如何在表格视图中设置注释的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序获取Web数据并将其存储在CD-db中.到目前为止,FirstViewController(MKMapView)将CD-db提取到NSMutableArray中,并使用其值通过从db获取自定义对象的数组来绘制位置.我在创建批注(引脚)时通过for循环.每个插针的距离属性都是通过计算得出的,该计算用于我从userLocation到每个插针的距离.

此应用程序在tabbarcontroller中运行,另一个选项卡是这些位置的表格视图.我通过获取CD-db并在cellForRowAtIndexPath方法中获取数组的值,然后将这些值放入cell.textLabel等中,来获取该tableview的值.

我的问题是,由于从userLocation到每个引脚的距离是在mapview控制器上计算的,我如何在tableview控制器上获得这些距离?

解决方案

您可以将mapview控制器设置为tableview的数据源.这样,只有一个viewcontroller会获取数据.构建mapview控制器的自定义对象数组后,即可用于响应所有tableview数据源调用,例如cellForRowAtIndexpath和numberOfRowsInSection

I have an app that fetches web data and stores it in CD-db. So far, FirstViewController (MKMapView) fetches CD-db into NSMutableArray and uses its values to plot locations by getting the array of custom objects from the db. I cycle thru a for loop while creating the annotation (pin). Each pin gets its distance property set from a calculation I use for the distance from userLocation to each pin.

This app runs in a tabbarcontroller and the other tab is a tableview listing of these locations. I get the values for that tableview by fetching the CD-db and getting the array's values at cellForRowAtIndexPath method and putting the values into the cell.textLabel etc...

My question is, since the distances from userLocation to each pin are calculated on the mapview controller, how do I get those distances on the tableview controller?

解决方案

You could set the mapview controller as the tableview's datasource. That way only one viewcontroller fetches data. Once you build the mapview controller's array of custom objects it can be used to respond to all the tableview datasource calls such as cellForRowAtIndexpath and numberOfRowsInSection

这篇关于如何在表格视图中设置注释的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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