NSTreeNode mutableChildNodes 无法正常工作?
我完全困惑为什么这不起作用。我正在尝试将新的 NSTreeNode 插入到子节点的可变数组中。下面是代码:
NSTreeNode *newNode = [[NSTreeNode alloc] init];
NSMutableArray *children = [anExistingParentTreeNode mutableChildNodes];
[children addObject:newNode];
执行后,我收到各种错误:
- -[NSCFSet initWithObjects:count:]: attempts to insert nil object at objects[0]
- -[NSTreeNode _tearDownObserving]: unrecognized selected 选择器发送到实例 0x2000bff40
- 严重的应用程序错误。在核心数据更改处理期间捕获异常: -[NSTreeNode _tearDownObserving]:无法识别的选择器发送到实例 0x2000bff40 with userInfo (null)
这些错误似乎正在处理 KVO 内容。有人在使用 mutableChildNodes 时遇到过类似的错误吗?非常感谢任何帮助。
注意:底层 NSTreeController 通过托管对象上下文绑定到核心数据。
I'm totally baffled why this is not working. I'm trying to insert a new NSTreeNode into a mutable array of child nodes. Here's the code:
NSTreeNode *newNode = [[NSTreeNode alloc] init];
NSMutableArray *children = [anExistingParentTreeNode mutableChildNodes];
[children addObject:newNode];
Upon execution I get all sorts of errors:
- -[NSCFSet initWithObjects:count:]: attempt to insert nil object at objects[0]
- -[NSTreeNode _tearDownObserving]: unrecognized selector sent to instance 0x2000bff40
- Serious application error. Exception was caught during Core Data change processing: -[NSTreeNode _tearDownObserving]: unrecognized selector sent to instance 0x2000bff40 with userInfo (null)
The errors seem to be dealing with KVO stuff. Has anybody encountered errors like these using mutableChildNodes? Any help is greatly appreciated.
Note: The underlying NSTreeController IS bound to core data via managed object context.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道是你没有正确初始化
newNode
对象?为该类定义的唯一
init
方法是:当您使用
init
时,您只需使用从NSObject
继承的默认实现。通常,一个类有一个或多个指定的初始值设定项,但对于
NSTreeNode
来说,我看不到它在文档中指定。但是,由于只为该类定义了一个初始值设定项,并且没有 setter 方法来在稍后阶段设置所表示的对象,因此我得出的结论是initWithRepresentedObject:
是该类的指定初始值设定项。关于初始化器: http://developer.apple .com/library/ios/#documentation/general/conceptual/DevPedia-CocoaCore/MultipleInitializers.html
Could it be that you have not initialized the
newNode
object correctly?The only
init
method defined for the class is:When you use
init
, you just use the default implementation inherited fromNSObject
.Normally, a class has one or more designated initializers, but in the case of
NSTreeNode
, I can't see that it is specified in the docs. However, since there is only one initializer defined for the class, and no setter methods to set the represented object at a later stage, I'd conclude thatinitWithRepresentedObject:
is the designated initializer of the class.About initializers: http://developer.apple.com/library/ios/#documentation/general/conceptual/DevPedia-CocoaCore/MultipleInitializers.html
请参阅我对原始问题的最后评论。
Refer to my last comment on the original question.