表达不兼容类型'id <mkannotation>'

时间:2016-10-18 22:35:36

标签: ios objective-c mkmapview 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中以* ann:

创建此警告
 Initializing 'MapViewController *__strong' with an expression of incompatible type 'id<MKAnnotation>'

如何摆脱这种警告? 尽管有警告,一切正常。

非常感谢你指出我正确的方向。 马丁

1 个答案:

答案 0 :(得分:0)

改变这个:

MapViewController *ann = [[_mapView annotations] objectAtIndex:i];

为:

id<MKAnnotation> ann = [[_mapView annotations] objectAtIndex:i];

因为[_mapView annotations]返回id<MKAnnotation数组,而不是MapViewController数组。