与自定义MKAnnotationView不兼容的指针

时间:2016-09-16 18:44:54

标签: ios objective-c xcode mkannotationview

在我的出租车应用程序中,我创建了一个自定义MKAnnotationView来显示驱动程序的估计位置。这很简单:

#import <MapKit/MapKit.h>

@interface EstimatedArrivalView : MKAnnotationView

- (void)setText:(NSString *)min :(NSString *)time;

@end

但是,当我尝试在ViewController上实现以下代码时:

EstimatedArrivalView *av = [_fullScreenMapView viewForAnnotation:driverPoint];
[av setText:@"MIN" : [NSString stringWithFormat:@"%d", etaTimeCount]];

我收到以下警告:

Incompatible pointer types initializing 'EstimatedArrivalView *' with an expression of type 'MKAnnotationView * _Nullable'

据我了解,我正在将EstimatedArrivalView初始化为MKAnnotationView。为什么警告?

1 个答案:

答案 0 :(得分:1)

我认为要解决此错误,您应该尝试将MKAnnotationView转换为EstimatedArrivalView,如下所示:

EstimatedArrivalView *av = (EstimatedArrivalView *)[_fullScreenMapView viewForAnnotation:driverPoint];