【问题标题】:Warning: incompatible pointer type on updating code警告:更新代码时指针类型不兼容
【发布时间】:2017-08-12 06:31:31
【问题描述】:

我正在尝试删除一些用于在 MapView 中创建叠加层的贬低代码,现在我正面临这个警告:

从结果类型为“MKOverlayView * _Nonnull”的函数返回“MKCircleRenderer *”的不兼容指针类型

我已经阅读了很多关于这个问题的问答,但直到现在我都无法弄清楚。我的代码有什么问题?

// 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;
}

【问题讨论】:

    标签: ios objective-c pointers mkmapview


    【解决方案1】:

    错误说 circleViewMKCircleRenderer * 的类型,但您的返回类型是 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 请提供反馈,如果它解决了您的问题
    • 是的。我AFK了一会儿。我会接受你的回答。非常感谢!
    猜你喜欢
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多