OGeek|极客世界-中国程序员成长平台

标题: ios - ARC - 当 UIViewController 设置为 nil 时,手势识别器和 KVO 是否被处理? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:38
标题: ios - ARC - 当 UIViewController 设置为 nil 时,手势识别器和 KVO 是否被处理?

我的问题很简单:当 UIViewController 设置为 nil 时,手势识别器和 KVO 是否被清除?

我有一个项目,用户可以在其中创建和删除一些复杂的基于 UIViewController 的实例。这些存储在 NSMutableArray 中。

如果我只是从数组中删除实例,然后将其设置为 nil(我猜这是多余的),实例的所有 @properties 是否会被清除(假设没有其他对它们的引用)?

编辑 当我不管理 KVO 时,我会收到下面的警报(错误) - 所以我猜答案是“不”

An instance 0xce26d40 of class Track 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: 0x7530300> Context: 0x0, Property: 0x75320f0>



Best Answer-推荐答案


一个对象拥有它的'@properties'(假设它们是strongretain)。并且 View 拥有添加到其中的任何手势识别器。所以当对象被释放时,它的属性和识别器将被释放,如果没有其他人拥有它们,就会被释放。

键值观察者和通知观察者需要在被释放之前手动取消订阅。

关于ios - ARC - 当 UIViewController 设置为 nil 时,手势识别器和 KVO 是否被处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9911570/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4