【发布时间】:2014-12-06 21:14:40
【问题描述】:
我已将我的appDelegate 类设置为CLLocationManager 的代表。在委托的didUpdateLocations 方法中,我创建了一条折线。我使用[self.firstViewController.currentMap addOverlay:self.polyline level:MKOverlayLevelAboveRoads] 将折线添加到地图视图中。但是,它对我的地图视图的实际实例没有影响,因为它认为self.firstViewController.currentMap 是nil。有没有办法以某种方式将地图实例传递给didUpdateLocations,以便将叠加层添加到MKMapView 的现有实例?
【问题讨论】:
-
如果它认为
self.firstViewController.currentMap是nil,它就是nil。您可以尝试正确设置它,如果没有看到任何代码,我们无法告诉更多。您可以添加一个指向appDelegate的弱指针,当您创建MKMapView对象时,您可以使该指针指向它。然后,您将拥有指向该MKMapView对象的直接指针,而不是使用firstViewController代理。 -
非常感谢!将
MKMapView作为弱属性添加到AppDelegate,然后在地图视图控制器的viewDidLoad方法中设置appDelegate.currentMap = self.currentMap对我有用。
标签: ios objective-c delegates mkmapview cllocationmanager