我有一些问题的MKMapView /注释/ UINavigationController的。基本上,我使用UINavigationController管理我的视图;我的一个视图包含一个MKMapView,并使用addAnnotations方法在其上添加注释(10到200)。addAnnotations问题(内存管理也许?)
一切工作,除了一件事罚款:如果我定位我的UINavigationController“太快”,iPhone模拟器死机,接收“EXC错误访问”的信号。例如,如果我加载包含MKMapView的视图并立即按下UINavigationController导航栏中的“返回”按钮,我就会得到信号。我认为问题出在addAnnotations方法上:当我的MKMapView被加载时,我给它添加了注释,但它看起来像所有事情都是异步完成的。如果我在按“返回”按钮之前等待一秒钟,我不会出错,但如果我速度太快,就会崩溃。如果我删除addAnnotations行,则完全没有错误。我想这是因为我的视图是在添加注释方法完成工作之前由UINavigationController发布的。
任何这个好的解决方案?我不希望用户等待(例如显示加载视图);我想解决方案可能是一个更好的内存管理,但我不明白我能做到这一点。
if(DEBUG_MODE) { NSLog(@"Creating array of placemarks : begin"); }
self.placemarkCache = [[NSMutableArray alloc] init];
// Loading placemarks for a placemark dictionary
NSArray *sortedKeys = [[self.placemarkDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
for (id key in sortedKeys) {
MyPlacemark *currentPlacemark = [self.placemarkDictionary objectForKey:key];
[self.placemarkCache addObject:currentPlacemark];
[currentPlacemark release];
}
if(DEBUG_MODE) { NSLog(@"Creating array of placemarks : done"); }
if(DEBUG_MODE) { NSLog(@"Adding placemarks : begin"); }
[self.mapView addAnnotations:self.placemarkCache];
if(DEBUG_MODE) { NSLog(@"Adding placemarks : done"); }
在这个例子中,在地图上显示任何东西之前,我会看到“添加地标:完成”消息。
这是完全相同的问题,它的工作:) 现在听起来很明显... 感谢您的回答! – Vivi 2009-09-07 16:41:39
您的链接不再有效。 – J2theC 2013-06-07 20:28:57