我试图摆脱一些用于在MapView中创建叠加层的已编译代码,现在我正面临这个警告:
不兼容的指针类型返回' MKCircleRenderer *'来自结果类型为' MKOverlayView * _Nonnull'
的函数我已经在这个问题上阅读了很多Q& A但直到现在我还是无法弄明白。我的代码出了什么问题?
// 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;
}
答案 0 :(得分:0)
错误表示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;
}