不兼容类型的表达式 'id<MKAnnotation>'
Expression of incompatible type 'id<MKAnnotation>'
我有这段代码
- (void)pinDropped {
StoreData *myStore = [StoreData sharedStore];
for (NSUInteger i = 0; i < annotations.count; i++) {
MapViewController *ann = [[_mapView annotations] objectAtIndex:i];
NSString *myStoreString = [NSString stringWithFormat:@"%@", myStore.myUebergabe];
NSString *myAnnTitleString = [NSString stringWithFormat:@"%@", ann.title];
if ([myStoreString isEqual:myAnnTitleString]) {
[_mapView selectAnnotation:[_mapView.annotations objectAtIndex:i] animated:YES];
}
}
}
它在 Xcode at *ann:
中创建了这个警告
Initializing 'MapViewController *__strong' with an expression of incompatible type 'id<MKAnnotation>'
如何摆脱这个警告?
尽管有警告,但一切正常。
非常感谢您为我指明了正确的方向。
马丁
改变这个:
MapViewController *ann = [[_mapView annotations] objectAtIndex:i];
至:
id<MKAnnotation> ann = [[_mapView annotations] objectAtIndex:i];
因为 [_mapView annotations]
returns 是 id<MKAnnotation
的数组,而不是 MapViewController
的数组。
我有这段代码
- (void)pinDropped {
StoreData *myStore = [StoreData sharedStore];
for (NSUInteger i = 0; i < annotations.count; i++) {
MapViewController *ann = [[_mapView annotations] objectAtIndex:i];
NSString *myStoreString = [NSString stringWithFormat:@"%@", myStore.myUebergabe];
NSString *myAnnTitleString = [NSString stringWithFormat:@"%@", ann.title];
if ([myStoreString isEqual:myAnnTitleString]) {
[_mapView selectAnnotation:[_mapView.annotations objectAtIndex:i] animated:YES];
}
} }
它在 Xcode at *ann:
中创建了这个警告 Initializing 'MapViewController *__strong' with an expression of incompatible type 'id<MKAnnotation>'
如何摆脱这个警告? 尽管有警告,但一切正常。
非常感谢您为我指明了正确的方向。 马丁
改变这个:
MapViewController *ann = [[_mapView annotations] objectAtIndex:i];
至:
id<MKAnnotation> ann = [[_mapView annotations] objectAtIndex:i];
因为 [_mapView annotations]
returns 是 id<MKAnnotation
的数组,而不是 MapViewController
的数组。