类的实例被释放,而关键值观察者仍然在其中注册

时间:2013-08-29 07:39:03

标签: ios mapkit mkannotation

我正在添加注释,我的地图上应该有5个注释引脚,但只显示2个,并显示此错误:

  

类Annotation的实例0x9d8e720在键时被释放   价值观察员仍在注册。观察信息是   泄露,甚至可能被错误地附着在其他物体上。   在NSKVODeallocateBreak上设置断点以停止h

//NUH COORDINATES
#define NUH_latitude 1.293700; 
#define NUH_longitude 103.783353;

//span
#define the_span 0.002f;

//NHGP COORDINATES!
#define NHGP_latitude 1.295938;
#define NHGP_longitude 103.782857;

//NUHER COORDINATES
#define NUHER_latitude 1.294968;
#define NUHER_longitude 103.783716;

//NUCIS COORDINATES
#define NUCIS_latitude 1.293149;
#define NUCIS_longitude 103.783464;

//Viva-UCCC COORDINATES!
#define VivaUCCC_latitude 1.294099;
#define VivaUCCC_longitude 103.783233;

//span
MKCoordinateSpan span;
span.latitudeDelta = the_span;
span.longitudeDelta = the_span;
MKCoordinateRegion myRegion;

//center
CLLocationCoordinate2D center;
center.latitude = NUH_latitude;
center.longitude = NUH_longitude;
myRegion.center =center;
myRegion.span = span;
[mapview setRegion:myRegion animated:YES];

//annotation
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
Annotation * myAnn;

//NUH location
myAnn = [[Annotation alloc] init];
location.latitude = NUH_longitude;
location.longitude = NUH_longitude;
myAnn.coordinate = location;
myAnn.title = @"NUH";
[locations addObject:myAnn];

//NHGP location
myAnn = [[Annotation alloc] init];
location.latitude = NHGP_latitude;
location.longitude = NHGP_longitude;
myAnn.coordinate = location;
myAnn.title = @"National Healthcare Group Polyclinic ";
[locations addObject:myAnn];

//NUHER location
myAnn = [[Annotation alloc] init];
location.latitude = NUHER_longitude;
location.longitude = NUHER_longitude;
myAnn.coordinate = location;
myAnn.title = @"National University Hospital Emergency Room";
[locations addObject:myAnn];

//NUCIS location
myAnn = [[Annotation alloc] init];
location.latitude = NUCIS_longitude;
location.longitude = NUCIS_longitude;
myAnn.coordinate = location;
myAnn.title = @"National University Cancer Institute Singapore";
[locations addObject:myAnn];

//Viva-UCCC location
myAnn = [[Annotation alloc] init];
location.latitude = VivaUCCC_latitude;
location.longitude = VivaUCCC_longitude;
myAnn.coordinate = location;
myAnn.title = @"Viva-University Children's Cancer Centre";
[locations addObject:myAnn];

[self.mapview addAnnotations:locations];

2 个答案:

答案 0 :(得分:2)

你已经为NUH,NUHER和NUCIS的纬度指定了经度。它们不会显示在您想要的位置(这就是您只看到2的原因),我认为错误是因为这些值对于纬度无效。

//NUH location
location.latitude = NUH_longitude; // <-- should be NUH_latitude
... 
//NUHER location
location.latitude = NUHER_longitude; // <-- should be NUHER_latitude
... 
//NUCIS location
location.latitude = NUCIS_longitude; // <-- should be NUCIS_latitude

答案 1 :(得分:0)

可能是因为你不断重新分配同一个myAnn变量。您应该尝试创建多个Annotation,如果必须,可以将它们称为myAnn1,myAnn2。

如果你有超过3个这样的东西,你应该考虑制作一个集合并循环遍历它而不是逐个创建它们