我正在对一个实现 . 的类进行子类MKMapViewDelegate
化。我也在超类中设置委托,但我的 -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
方法没有被调用。这是我的代码
我的超类代码
// RecentPhotosMapViewController.h
@interface RecentPhotosMapViewController : UIViewController <MKMapViewDelegate>
@property (nonatomic,strong) NSArray *annotations;
@property(nonatomic,weak) IBOutlet MKMapView *mapView;
@end
// RecentPhotosMapViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
// load annotation data
self.mapView.delegate = self;
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation{
MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
// safety code
if(!aView){
aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
aView.canShowCallout = YES;
aView.leftCalloutAccessoryView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
aView.annotation = annotation;
[(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
return aView;
}
我的子类代码
// RecentPhotosMapViewControllerWithAnnotationData.h
@interface RecentPhotosMapViewControllerWithAnnotationData : RecentPhotosMapViewController
@end
RecentPhotosMapViewControllerWithAnnotationData.m 文件
-(void) viewDidLoad{
// extract annotation data.....
// set zoom level
[super viewDidLoad];
}
然而-(void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view method is called
任何帮助表示赞赏