简体   繁体   English

Mapbox selectAnnotation在ViewDidLoad中不起作用,或在ViewDidAppear中首次使用

[英]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.

相关问题 becomeFirstResponder在viewDidAppear中工作,但在viewDidLoad中不起作用 - becomeFirstResponder works in viewDidAppear but doesn't work in viewDidLoad viewDidLoad 中的快速设置属性不起作用,但在 viewDidAppear 中有效 - swift setting properties in viewDidLoad doesn't work but works in viewDidAppear Mapview的selectAnnotation方法不适用于iOS7 - selectAnnotation method of Mapview doesn't work for iOS7 将popViewControllerAnimated:放置在viewDidLoad或viewDidAppear中将不起作用 - placing popViewControllerAnimated: in viewDidLoad or viewDidAppear will not work 当UITabBarController在屏幕上显示第一个选项卡时,调用什么方法? viewDidAppear不起作用 - What method is called when UITabBarController shows first tab on screen? viewDidAppear doesn't work 无法选择使用viewDidLoad或viewDidAppear - Cannot get segue to work with viewDidLoad or viewDidAppear 为什么不在viewDidLoad中执行SegueWithIdentifier工作? - Why doesn't performSegueWithIdentifier work inside viewDidLoad? contentOffset.x 在 vi​​ewDidLoad 中不起作用 - contentOffset.x doesn't work in viewDidLoad iPhone-GCD第一次不起作用 - iPhone - GCD doesn't work for the first time 在ViewDidAppear上更改核心动画持续时间似乎不起作用 - changing Core Animation duration on ViewDidAppear doesn't seem to work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM