[英]Mapbox selectAnnotation doesn't work in ViewDidLoad or first time in ViewDidAppear
I have a master-detail application, and my details page is a map. 我有一个主从应用程序,而我的详细信息页面是一张地图。 When I click on the element in the Master list, the map with whole bunch of markers shows up, zooms/pans into a specific location, and an annotation pops up describing what this location is. 当我单击“母版”列表中的元素时,将显示带有一堆标记的地图,将地图缩放/平移到特定位置,并弹出说明该位置的注释。
The implementation is pretty simple, so I thought. 实现非常简单,所以我认为。 In my viewDidAppear, I go through the list of annotations in my mapview and just call [mapView selectAnnotation: myAnnotation animated: FALSE]
and it works fine. 在我的viewDidAppear中,我浏览了[mapView selectAnnotation: myAnnotation animated: FALSE]
中的注释列表,然后调用[mapView selectAnnotation: myAnnotation animated: FALSE]
,它可以正常工作。 BUT NOT THE FIRST TIME! 但是不是第一次!
I populate my map in ViewDidLoad, and the first time the ViewDidAppear is called, the mapView.annotations array is still empty. 我将地图填充到ViewDidLoad中,并且第一次调用ViewDidAppear时,mapView.annotations数组仍然为空。 Is there a simple way to make it work even when I first enter the details view? 即使我第一次进入详细信息视图时,是否有一种简单的方法可以使其正常工作? Or do I have to create and populate the map in the AppDelegate? 还是我必须在AppDelegate中创建并填充地图?
Try using MGLMapViewDelegate and especially 尝试使用MGLMapViewDelegate,尤其是
func mapViewDidFinishLoadingMap(mapView: MGLMapView) {
// your code here
}
也许您可以在DetailViewController上定义一个方法,然后在触发诸如tableview的didselect或prepareForSegue之类的方法时,您必须获取DetailViewController的实例,最后,可以使用此实例调用用户定义的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.