繁体   English   中英

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

[英]subclassing a class implementing MKMapViewDelegate but MKMapViewDelegate method not called

我正在对实现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

LatestPhotosMapViewControllerWithAnnotationData.m文件

      -(void) viewDidLoad{


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


[super viewDidLoad];

}

但是-(void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view method is called

任何帮助表示赞赏

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

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

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

LatestPhotosMapViewControllerWithAnnotationData.m

-(void) viewDidLoad
{

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

[super viewDidLoad];

self.mapView.delegate = self;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM