首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实现MKMapViewDelegate但未调用MKMapViewDelegate方法的类的子类化

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

Stack Overflow用户
提问于 2013-02-23 13:50:00
回答 2查看 237关注 0票数 0

我是subClassing,一个实现了MKMapViewDelegate.I的类,也在超类中设置了委托,但是我的-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation方法没有被调用。以下是我的代码

我的superClass代码

代码语言:javascript
复制
 //  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;
}

我的子类代码

代码语言:javascript
复制
     //  RecentPhotosMapViewControllerWithAnnotationData.h
     @interface RecentPhotosMapViewControllerWithAnnotationData : RecentPhotosMapViewController
     @end

RecentPhotosMapViewControllerWithAnnotationData.m文件

代码语言:javascript
复制
      -(void) viewDidLoad{


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


[super viewDidLoad];

}

然而,-(void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view method is called

任何帮助我们都将不胜感激

EN

回答 2

Stack Overflow用户

发布于 2013-02-23 13:52:48

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

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

票数 1
EN

Stack Overflow用户

发布于 2013-02-23 14:09:24

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

RecentPhotosMapViewControllerWithAnnotationData.m

代码语言:javascript
复制
-(void) viewDidLoad
{

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

[super viewDidLoad];

self.mapView.delegate = self;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15037557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档