MapKit 自定义注释已添加到地图中,但在地图上不可见
我有一个带有 mapView 和 UITableView 的界面。从服务器加载数据,创建注释并使用
[mapView addAnnotation:truck]
返回的数组填充表格视图
添加到地图,然后使用从[mapView comments]< /code>
一旦此过程完成,我会在每次单击表格中的单元格时调用 [[mapView comments] count]
来检查地图上的注释数量,并且其等于它的数量应该是这样,所以所有注释都被添加到地图视图上,但由于某种原因我在模拟器中看不到任何注释。
图像的命名与在自定义 AnnotationView 中分配的名称相同,loadAnnotation 函数已正确完成,等等...我不知道它可能是什么,但我查看了图像文件与其加载位置之间的关联一百次发现差异,但一切看起来都很好。
一个有趣的点是,当我在单击单元格后打印和坐标值时(请记住该数据直接来自 [mapView 注释]
,它看起来不错......但无论出于何种原因,注释视图都没有被显示) 所以我想
如果我能回答一个问题,那么地图视图包含多个注释但没有在地图上显示任何注释的可能原因是什么?
谢谢
已编辑重要的附加信息
模拟器中地图上显示的内容与我在 mapView 对象中看到的内容之间似乎存在脱节,例如,当我在 tableView 中选择一行时,我正在调用:
[mapView setRegion] :MKCoordinateRegionMake([注释坐标], MKCo整理SpanMake(.01, .01)) 动画:YES];
这对模拟器中的地图没有影响,我已经检查过传递的坐标实际上是有效的。坐标,但这似乎并不重要,因为地图没有响应。我认为我的 .xib 可能有问题,但它全部连接正确。 delegate 是插座,mapView 作为引用插座。
现在有人明白可能会发生什么吗?
I have an interface with a mapView and UITableView. Data is loaded from a server, and the annotations are created and added to the map with
[mapView addAnnotation:truck]
the tableview is then populated using the array thats retured from
[mapView annotations]
once this process is completed, i check the number of annotations on the map with [[mapView annotations] count]
called whenever i click on a cell in the table and its equal to the number it ought to be, so all the annotations are getting added onto the mapView, but for some reason I cant see any annotations in the simulator.
The images are named just as they are assigned in the custom AnnotationView, the loadAnnotation function is done properly, etc... i dont know what it could be but ive looked at the associate between the image file and wheres its loaded a hundred times to find a discrepancy, but it all looks fine.
One interesting point is that when i print and coordinate value after clicking on the cell (remember this data comes straight from [mapView annotations]
, it looks good... but for whatever reason the annotation view isnt being displayed.
so i suppose if i could have the answer to one question it would be, what are possible causes for a mapView to contain several annotations, but to not show any on the map?
Thanks
EDITED WITH IMPORTANT ADDITIONAL INFO
There appears to be a disconnect between what is being displayed on my map in the simulator and what im seeing in the mapView object. For example, when i select a row in the tableView, I am calling:
[mapView setRegion:MKCoordinateRegionMake([annotation coordinate], MKCoordinateSpanMake(.01, .01)) animated:YES];
and this has no effect on the map in the simulator. I have checked that the coordinate being passed is actually a valid coordinate, but it doesnt seem to matter because the map is being unresponsive. I thought it could be something wrong with my .xib, but its all connected properly. delegate is the outlet and mapView as a referencing outlet.
Does anyone now understand what may be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来确实像是丢失的图像。
尝试用 MKPinAnnotations 替换您的自定义注释进行测试,然后查看您的注释是否可见。
您是否实现了以下委托功能?
This really looks like missing images.
Try replacing your custom annotations with MKPinAnnotations to test, and see if your annotations are visible then.
Have you implemented the following delegate function ?
这一行:
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
正在把一切搞乱。一旦我将其注释掉,该应用程序就开始正常工作。
This line:
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
was creating messing everything up. once i commented it out, the app began working fine.