【发布时间】:2013-03-29 13:29:20
【问题描述】:
我的 MKAnnotations 有一个自定义类,我想覆盖默认的 mapView:viewForAnnotatation 方法,以便在标注中添加额外信息。当我在代码中设置我的委托时(根据下面的代码),注释会被丢弃在地图上并且是可选择的,但我的 mapView:viewForAnnoation 永远不会被调用。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(@"viewForAnnotation: called");
MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"mapPin"];
if(!aView){
aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"mapPin"];
}
aView.annotation = annotation;
return aView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.mapView.delegate = self;
}
我知道委托正在设置,因为我可以覆盖方法 -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view,并且当我选择注释时会看到 NSLog。
当我从在代码中设置委托更改为在情节提要中设置它时,会调用该方法(NSLog(@"viewForAnnotation: called"); 语句出现)但注释不会出现在地图上,有时会出现此错误出现:
<Error>: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedImageBlockData: bad readSession [0x8618480]
【问题讨论】:
标签: iphone ios objective-c mapkit mkannotation