Iphone 子类化实现MKMapViewDelegate但未调用MKMapViewDelegate方法的类

Iphone 子类化实现MKMapViewDelegate但未调用MKMapViewDelegate方法的类,iphone,ios,objective-c,Iphone,Ios,Objective C,我正在子类化一个实现MKMapViewDelegate的类。我还在超类中设置委托,但我的-(MKAnnotationView*)mapView:(MKMapView*)mapviewforannotation:(id)annotation方法未被调用。这是我的密码 我的超类代码 // RecentPhotosMapViewController.h @interface RecentPhotosMapViewController : UIViewController <MKMapVie

我正在子类化一个实现
MKMapViewDelegate
的类。我还在超类中设置委托,但我的
-(MKAnnotationView*)mapView:(MKMapView*)mapviewforannotation:(id)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.m文件

      -(void) viewDidLoad{


// extract annotation data.....
// set zoom level


[super viewDidLoad];

}
但是,调用了
-(void)mapView:(MKMapView*)mapView didSelectAnnotationView:(MKAnnotationView*)视图方法


感谢您的帮助

尝试移动
[super viewDidLoad]
作为子类中的
viewDidLoad
中的第一行


当您调用设置委托的
[super viewDidLoad]
时,一切都已发生。

将mapView委托赋值行保留为派生类viewDidLoad方法的最后一行:

RecentPhotosMapViewControllerWithAnnotationData.m

-(void) viewDidLoad
{

// extract annotation data.....
// set zoom level

[super viewDidLoad];

self.mapView.delegate = self;

}

感谢它的帮助,但首先我需要在我的子类中调用我的[super viewDidLoad]之前设置我的模态。您可能需要重新考虑为什么要这样做,但您可以在
[super viewDidLoad]之前移动一些内容但是请记住,可能有更好的方法来做你想做的事情。
-(void) viewDidLoad
{

// extract annotation data.....
// set zoom level

[super viewDidLoad];

self.mapView.delegate = self;

}