class - (MyAnnotation批注)已取消分配

时间:2013-03-06 07:12:10

标签: ios objective-c cocoa-touch mapkit

  

类的实例0x11d0ce4b0 - (MyAnnotation注释)是   当关键价值观察员仍然注册时,已经解除分配。   观察信息被泄露,甚至可能被错误地附上   到其他一些对象。在NSKVODeallocateBreak上设置断点以停止   在调试器中。这是当前的观察信息:

但我在我的dealloc方法上放了一个断点,在那里,我取消注册这些通知。调用Dealloc,我确实检查它是同一个对象,并且取消注册的所有调用都在那里。所以我不知道如何移除观察者。

1 个答案:

答案 0 :(得分:1)

创建自定义AnnotationView

#import <MapKit/MapKit.h>

@interface AnnotationView : MKPlacemark

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *subtitle;


@end

并在.m file

#import "AnnotationView.h"

@implementation AnnotationView

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary
{
    if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary]))
    {
        self.coordinate = coordinate;
    }
    return self;
}

@end

//使用注释在相关的#import "AnnotationView.h"

中添加.m file
CLLocationCoordinate2D pCoordinate ;
pCoordinate.latitude = LatValue;
pCoordinate.longitude = LanValue;

// Create Obj Of  AnnotationView class  

AnnotationView *annotation = [[AnnotationView alloc] initWithCoordinate:pCoordinate addressDictionary:nil] ;

    annotation.title = @"I m Here";
    annotation.subtitle = @"This is Sub Tiitle";

[self.mapView addAnnotation:annotation];

以上是简单的示例如何创建AnnotationView