NSTreeNode mutableChildNodes 无法正常工作?

发布于 2024-12-18 12:45:47 字数 683 浏览 2 评论 0原文

我完全困惑为什么这不起作用。我正在尝试将新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铃予 2024-12-25 12:45:47

难道是你没有正确初始化newNode对象?

为该类定义的唯一 init 方法是:

- (id)initWithRepresentedObject:(id)modelObject

当您使用 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 newNodeobject correctly?

The only init method defined for the class is:

- (id)initWithRepresentedObject:(id)modelObject

When you use init, you just use the default implementation inherited from NSObject.

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 that initWithRepresentedObject: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文