Iphone 发送';地图注释*;至不兼容类型的参数';id<;MKAnnotation>';
我在下面提到的行中收到警告:Iphone 发送';地图注释*;至不兼容类型的参数';id<;MKAnnotation>';,iphone,Iphone,我在下面提到的行中收到警告: [self.mapView addAnnotation:addressAnnotation]; 警告是: Sending 'MapAnnotation *__strong' to parameter of incompatible type 'id<MKAnnotation>' 正在向不兼容类型“id”的参数发送“MapAnnotation*\uuu strong” 因为我提到过类似的帖子,我必须提到,这个类的头文件包括,并且MapAnnotati
[self.mapView addAnnotation:addressAnnotation];
警告是:
Sending 'MapAnnotation *__strong' to parameter of incompatible type 'id<MKAnnotation>'
正在向不兼容类型“id”的参数发送“MapAnnotation*\uuu strong”
因为我提到过类似的帖子,我必须提到,这个类的头文件包括
,并且MapAnnotation
类的转发声明也可用
请提出建议。要消除警告,您有两种选择:
@interface
语句中声明self类(无论该类是什么),以符合协议[self.mapView addAnnotation:addressAnnotation]代码>
为此:
[self.mapView addAnnotation:(id)addressAnnotation]代码>
我的解决方案是为addAnnotation添加“s”
[self.mapView addAnnotations:addressAnnotation];
“这个类”是指地图注释吗?例如:
@interface MapAnnotation:NSObject
您是否介意通过显示如何创建addressAnnotation对象来更精确地说明此错误Hi Niko,请在下面找到创建对象的代码<代码>代码addressLocation=@“未知”;addressAnnotation=[[MapAnnotation alloc]initWithTitle:(NSString*)地址位置和坐标:坐标];嘿,安娜,谢谢你的评论。我已经在MapAnnotation类中包含了警告,警告问题得到了解决。@Milad Rk我使用(id)解决方案来禁止在我的项目中出现类似的警告,谢谢。你能解释一下为什么这样做吗?还有更多关于声明自我的类。顺便说一下,我是n00b;)。你知道是什么导致了这个问题吗?有时候我明白,有时候我不明白/