mle*_*s54 17 iphone reverse-geocoding mkannotationview
当我的观点消失时,我收到以下消息:
An instance 0x1c11e0 of class MKAnnotationView 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:
Run Code Online (Sandbox Code Playgroud)
(上下文:0x0,属性:0x1e98d0>)
定义和启动反向地理编码的代码是:
geo=[[MKReverseGeocoder alloc] initWithCoordinate:droppedAt];
geo.delegate=self;
[geo start];
Run Code Online (Sandbox Code Playgroud)
在我解除视图之前,我已经尝试将geo.delegate设置为nil.那太简单了.我也尝试过:
for (id <MKAnnotation> annotation in mvMap.annotations) {
[[mvMap viewForAnnotation:annotation] removeObserver:self forKeyPath:@"selected"];
}
Run Code Online (Sandbox Code Playgroud)
这引发了一个错误:
*由于未捕获的异常'NSRangeException'而终止应用程序,原因是:'无法删除"选中"的关键路径的观察者,因为它未注册为观察者.
我对注释代码的看法是:
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView *aView;
aView=(MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:annotation.title];
if (aView==nil)
aView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotation.title] autorelease];
else
aView.annotation=annotation;
[aView setImage:[UIImage imageNamed:selIcon]];
aView.canShowCallout=TRUE;
aView.draggable=YES;
return aView;
}
Run Code Online (Sandbox Code Playgroud)
在旋转的时候,我有点按下按钮并在这里翻转开关.想知道我能在这做什么吗?
Oli*_*lie 13
这里你可能有多个问题.对于您设置的每个代表,您应该在dealloc清除它.对于您设置的每个观察者,您应该清楚,与通知等相同.
所以你的dealloc应该有(输入网页浏览器,你可能需要调整):
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
for (id <MKAnnotation> annotation in mvMap.annotations)
{
// remove all observers, delegates and other outward pointers.
[[mvMap viewForAnnotation:annotation] removeObserver: self forKeyPath: path];
}
gel.delegate = nil;
// etc., your other stuff
[super dealloc]; // Only in non-ARC legacy code. Modern stuff skips this.
}
Run Code Online (Sandbox Code Playgroud)
完成您的设置(可能在viewDidLoad中)并确保您取消在那里执行的所有操作.特别是触发回调的任何事情.
| 归档时间: |
|
| 查看次数: |
17201 次 |
| 最近记录: |