问题描述:
我试图摆脱一些depricated代码在MapView创建覆盖,现在我facingh此警告兼容的指针类型从结果类型'MKOverlayView * _Nonnull'警告:</p> <p>不兼容的指针类型返回“MKCircleRenderer *”:在更新代码
我读过很多关于这个问题的Q &,但直到现在我还是无法弄清楚。我的代码有什么问题?
// Create overlay
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay{
MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleView.fillColor = [[UIColor cyanColor]colorWithAlphaComponent:0.5];
circleView.strokeColor = [[UIColor blueColor]colorWithAlphaComponent:0.8];
circleView.lineWidth = 1;
return circleView;
}
答
错误说circleView
是MKCircleRenderer *
类型,但是你的返回类型为MKOverlayView *
。这些类型应该是相同的。
- (MKCircleRenderer *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay{
MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleView.fillColor = [[UIColor cyanColor]colorWithAlphaComponent:0.5];
circleView.strokeColor = [[UIColor blueColor]colorWithAlphaComponent:0.8];
circleView.lineWidth = 1;
return circleView;
}
谢谢,你能给我提示如何做到这一点?我没有很多的经验(对不起) – A3O
@A3O我更新了我的答案,试一试 – 3stud1ant3
@ A3O请给出反馈,如果它解决了你的问题 – 3stud1ant3