MapKit addAnnotations:无效

时间:2012-04-26 11:46:28

标签: iphone ios ipad ios5 mapkit

我有代码:

if (self.annotations) [self.mapView addAnnotations:self.mapView.annotations];
NSLog(@"mapView: %@, anos:%@",self.mapView,self.mapView.annotations);

我得到下一个输出格式日志:

2012-04-26 14:35:53.823 FlickrClient[46441:11603] mapView: <MKMapView: 0x79c8b50; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x79c62b0>>, anos:(
)

据我所知,注释未添加到mapView 在此代码之前,我还有下一个日志记录:

for (id i in self.annotations)
{
    NSLog(@"%@, %i",i,[i conformsToProtocol:@protocol(MKAnnotation)]);
}

它给出了:

...
2012-04-26 14:35:53.766 FlickrClient[46441:11603] <TopPlaceAnnotation: 0x6d8a590>, 1
2012-04-26 14:35:53.767 FlickrClient[46441:11603] <TopPlaceAnnotation: 0x6d8a5a0>, 1
2012-04-26 14:35:53.767 FlickrClient[46441:11603] <TopPlaceAnnotation: 0x6d8a5b0>, 1
2012-04-26 14:35:53.819 FlickrClient[46441:11603] <TopPlaceAnnotation: 0x6d8a5c0>, 1
2012-04-26 14:35:53.819 FlickrClient[46441:11603] <TopPlaceAnnotation: 0x6d8a5d0>, 1
2012-04-26 14:35:53.819 FlickrClient[46441:11603] <TopPlaceAnnotation: 0x6d8a5e0>, 1
...

因此self.annotations存在并且全部符合MKAnnotation

我错过了什么吗?

1 个答案:

答案 0 :(得分:6)

我认为有一个小错误,

这一行:

if (self.annotations) [self.mapView addAnnotations:self.mapView.annotations];

应该是:

if (self.annotations) [self.mapView addAnnotations:self.annotations];