键值观察器和NSKVODeallocateBreak的错误 [英] Errors of key value observers and NSKVODeallocateBreak

查看:182
本文介绍了键值观察器和NSKVODeallocateBreak的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现UITableView作为包含5个表单元格的第一级视图控制器.击中任何这些单元将显示第二级视图.在此级别视图的左上方,有一个后退"按钮可返回到第一个级别视图.在第二级视图中,向左或向右滑动将连续显示与第一级视图中的那些相邻表单元格链接的相邻视图.

I'm implementing a UITableView as a first level view controller that contains 5 table cells. Hitting on any of these cells will present a second level view. At the top left of this level view, there is a "back" button to return to the first level view. At the second level view, swiping left or right will show adjacent views continuously that link to those adjacent table cells at the first level view.

运行后,从第一级视图到第二级视图都可以.但是,当点击后退"按钮时,从第二级视图返回到第一级视图,以下是我遇到的问题.

After running, from first level view to second level view it's ok. But when hitting the "back" button, going back to first level view from second level view, the following is the issue I got.

An instance 0x7a8f130 of class UIScrollView 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: (
Context: 0x0, Property: 0x9149570>
)

我找到了

- (void)viewDidUnload
{
    [super viewDidUnload];
    [self.scrollView removeObserver:self forKeyPath:@"frame"];
    [self.scrollView removeFromSuperview];
    _scrollView = nil;
}

我用来实现无限滚动视图控制器的GDIInfinitePageScrollViewController.m中的

.当我对此发表评论时,问题仍然存在.

in the GDIInfinitePageScrollViewController.m that I'm using to implement an infinite scroll view controller. When I commented this out, the issue is still there.

当我设置断点NSKVODeallocateBreak时,这就是我得到的

when I set breakpoint NSKVODeallocateBreak, here is what I got

0x1170ae0:  pushl  %ebp

但是我不知道这意味着什么.

but I have no idea about what it means.

有人知道如何解决此问题吗?

Does anyone know how to fix this issue?

推荐答案

收到该消息的原因是因为UIScrollView实例是在删除其观察者之前释放的.

The reason you are getting that message is because the UIScrollView instance is being released before its observers are removed.

已释放视图时,将调用-(void)viewDidUnload方法,因此删除观察者的调用为时已晚.此外,iOS 6和-(void)viewWillUnload不推荐使用此功能.

The method -(void) viewDidUnload is called when the view has already been released, so that call to remove the observer is too late. In addition, this has been deprecated with iOS 6, along with -(void) viewWillUnload.

作为替代方法,请在单击后退"按钮时尝试移除观察者.

As an alternative, try removing the observer when hitting the back button.

这篇关于键值观察器和NSKVODeallocateBreak的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆