macos - Cocoa 绑定(bind) - 收到 "deallocated while key value observers were still registered"警告

标签 macos cocoa core-data cocoa-bindings key-value-observing

我一直在 NSOutlineView 内的 NSTableCellView 中使用 Cocoa 绑定(bind),但将我自己的数据提供到 outlineView objectValueForTableColumn:byItem: 方法中(即不使用 NSArrayController 来存储内容)。它工作正常,直到我从表中删除一行,在表中获取托管对象并将其从上下文中删除,并且在 NSManagedObjectContextWillSaveNotification 观察器中,我更新数据模型并从大纲 View 中删除该行。但是当我这样做时,我收到以下警告:

An instance 0x10d922890 of class Log_Log_ 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 ....

设置断点并不能真正帮助识别问题。我知道有些东西正在观察 Log(正在执行绑定(bind)的 tableCellView)上的属性,但是当从大纲 View 中删除该行时,如何清理它?我重写了 Log 的 didTurnIntoFault 并且确实在 self.observationInfo 中得到了一个非零值,但我认为这不能帮助识别需要作为观察者删除的观察对象是什么观点。 我不确定为什么会发生这种情况,以及调试此问题以找到“绑定(bind)”观察者的违规对象的最佳方法是什么。

最佳答案

NSTableCellViews 被保存以供重用,因此你的僵尸式 cellView 保留了 objectValue。当您删除该行时,您可能希望将单元格 View 中的 objectValue 清空。

为此使用 NSTableViewDelegate didRemoveRowView:forRow 可能有意义。

关于macos - Cocoa 绑定(bind) - 收到 "deallocated while key value observers were still registered"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25029725/

相关文章:

ios - Swift Progress View 值传递函数

objective-c - 使用 Core Data 时是否可以使用复杂索引?

ios - 核心数据模型设计——反向关系

objective-c - 如何检查用户选择的文件我的沙盒应用程序是否有权写入?

macos - mac nodejs公共(public)目录权限 'Forbidden'

macos - OS X Storyboard : how to show a window programmatically?

macos - NSFileWrapper 支持延迟加载吗?

swift - nsbutton 单击没有调用操作方法 - cocoaprogramming with swift

macos - Leopard OSX 终端中主机名/用户的更改

iphone - NSURLRequest 设置 HTTP header