MKPolylineView initWithPolyLine: is deprecated in

2019-06-16 20:57发布

I am getting the following error: initWithPolyline: is deprecated: first deprecated in iOS 7.0

MKPolylineView *lineView = [[MKPolylineView alloc] 
       initWithPolyline:overlay];

What is the replacement method of instead of this ?

3条回答
forever°为你锁心
2楼-- · 2019-06-16 21:16

You will like to take a look to MKPolylineRenderer, specifically to -initWithPolyline (avalilable in iOS 7 and later).

查看更多
神经病院院长
3楼-- · 2019-06-16 21:18

You should use (MKOverlayRenderer *) type delegate instead of (MKOverlayView *) type delegate. And return MKPolylineRenderer instead of MKPolylineView.

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView
           rendererForOverlay:(id<MKOverlay>)overlay {

   MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
   renderer.strokeColor = [UIColor redColor];
   renderer.lineWidth = 5.0;

   return renderer;
}
查看更多
相关推荐>>
4楼-- · 2019-06-16 21:32

See the documentation for initWithPolyline:. Read the Deprecation Statement which says to use an MKPolylineRenderer object instead.

查看更多
登录 后发表回答