我是子類的一個實現MKMapViewDelegate
的類。我也在超類中設置委託,但是我的-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
方法沒有被調用。這裏是我的代碼子類化一個實現MKMapViewDelegate的類,但是MKMapViewDelegate方法不被調用
我超碼
// 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
任何幫助表示讚賞
感謝它幫助,但首先我需要做的設置我的模式之前我[超級viewDidLoad中]被稱爲在我的子類的任何其他建議。 – shaunak1111 2013-02-23 06:03:31
你可能要重新考慮你爲什麼這樣做,但你可以前的'[超級viewDidLoad中]還可以將一些東西;'但要記住,有可能是做你想要什麼更好的辦法。 – Ric 2013-02-23 06:09:20