类-(MyAnnotation注解)被释放 [英] class -(MyAnnotation annotation) was deallocated
问题描述
类-(MyAnnotation注解)的实例0x11d0ce4b0为 当关键值观察者仍在向其注册时,将其释放. 观察信息已泄漏,甚至可能被错误地附加 到其他对象.在NSKVODeallocateBreak上设置一个断点以停止 在调试器中.这是当前的观察信息:
An instance 0x11d0ce4b0 of class -(MyAnnotation annotation) was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
但是我在我的dealloc方法上放置了一个断点,在那里我为这些通知取消注册.调用了Dealloc,并且我检查了它是否是同一对象,并且所有取消注册的调用都在那里.所以我不知道怎么 不能删除观察者.
But I have put a breakpoint on my dealloc method, and in there, I do deregister for those notifications. Dealloc is called, and I did check that it was the same object, and all the calls to deregister are there. So I don't know how it could not be removing the observers.
推荐答案
创建自定义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
//使用注释在相关的.m file
中添加#import "AnnotationView.h"
:
// Use Annotation Add #import "AnnotationView.h"
in your relevant .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
.
Above is simple Example of how to create AnnotationView
.
这篇关于类-(MyAnnotation注解)被释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!