문제

I am using the Mapbox iOS SDK to show offline OpenStreetMaps data in my iOS app. I have successfully done this programatically, but now I would like to do this using the Interface Builder. To do so I have created a subclass of UIViewController with a .xib file and put a UIView into the main view of the xib. Then in the identity inspector I changed this view's Custom Class to RMMapView and put an IBOutlet into the header of of the UIViewController and connected it with the Custom RMMapView object in the xib.

@property (weak, nonatomic) IBOutlet RMMapView *mapView;

So far I think this should be correct. When I start the app the RMMapView is created in the nib and shows the default behavior, i.e. it shows a map with the "Example" watermarks. Therefore I need to set the appropriate tilesource, so far I did this in the viewDidLoad method of the ViewController, something like

 RMMBTilesSource *tileSource = [[RMMBTilesSource alloc] initWithTileSetResource:@"mymap" ofType:@"mbtiles"];

followed by

[self.mapView setTileSource:tileSource]

or alternatively

[self.mapView addTileSource:tileSource] 

However, even after these calls the mapView's RMTileSourcesContainer has still value nil and from what I can tell the set/addTileSource calls practically don't have an effect. In my opinion the problem is that in RMMapView initWithCoder has not been overwritten and therefore the RMMapView is not initialized properly through the nib, most importantly the RMTileSourcesContainer is not initialized. Is this really the case ? Why has initWitCoder not been overwritten ? How should I go about using RMMapView in the Interface Builder ? Thanks for your help!!

도움이 되었습니까?

해결책

You want to try this in -viewWillAppear: or later, not -viewDidLoad. Due to the way the RMMapView is based on UIScrollView, the map view needs to added to a live view hierarchy before it can set its parameters.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top