【问题标题】:MKMapViewDelegate is nota called when inside a subclass of MKMapView在 MKMapView 的子类中不调用 MKMapViewDelegate
【发布时间】:2012-07-27 22:17:20
【问题描述】:

我是 Objective C 的新手,但学得很快。我的项目非常完整,我已经实现了类,而不是委托等。

我正在使用 MKMapView 在地图上显示内容。我还需要用户点击会返回一些信息的 Pin 图,但我确实希望 MKViewMap 在发送信息之前做出一些估计。

因此,我对 MKMapView 进行了子类化,并且正在使用此类进行显示。但我没有接到代表的电话。当我以标准方式使用 MKViewMap 时,它可以正常工作。这是一些代码。子类有一个委托协议,这很好用

// .h 文件

#import < MapKit/MapKit.h >

@protocol MyMapViewDelegate < NSObject >

@required

- (void) ReturnAddressToHail:(NSString*) FullAddresse andNumber:(NSString*) FullNumber;
- (void) ReturnSelectedDriverHash:(NSString*) DriverHash;
@end


@interface MyMapViewClass : MKMapView < MKMapViewDelegate >

{

id < MyMapViewDelegate > delegate;

CLLocationCoordinate2D mapCenter;
NSDictionary *Info;
CLLocation * ClientNewLocation;

}

@property (retain) id delegate;

// .m 文件

#import "MyMapViewClass.h"
#import "NSObject+MapAnnotationHelper.h"

@implementation MyMapViewClass

@synthesize geoCoder;
@synthesize delegate;

self.delegate = self;


-(void) mapView:(MKMapView *) mapView regionDidChangeAnimated:(BOOL)animated

{

(void) self.updateAddress;
NSLog(@"regionchange delegate");

}

后者永远不会被调用。有什么想法吗?

【问题讨论】:

  • 我找到了解决方案。我不得不替换 self.delegate=self;与 super.delegate=self;还是谢谢

标签: delegates mkmapview subclass mkmapviewdelegate


【解决方案1】:

我相信你有你的理由,但文档声明你不应该继承 MKMapView,而是使用委托来改变它的行为。可能有更简单的方法来做你正在做的任何事情。

虽然您不应该继承 MKMapView 类本身,但您可以通过提供委托对象来获取有关地图视图行为的信息。

【讨论】:

    猜你喜欢
    • 2017-07-14
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2013-10-29
    相关资源
    最近更新 更多