NSOutlineView+NSTreeNode:我的自定义数据去哪儿了?
我正在设置一个绑定到 NSTreeController 的 NSOutlineView,该 NSTreeController 填充有 NSTreeNode
实例,后者使用 [NSTreeNode treeNodeWithRepresentedObject:...]
附加了我的自定义 NodeData 对象。 大纲视图渲染得很好,所有数据都按预期存在,一切都很好。
现在在大纲视图的委托中,我尝试通过 outlineView:willDisplayCell:forTableColumn:item:
方法。
但是,item
参数不会返回我的自定义数据!
id stuff = [item representedObject];
产生一个 NSTreeNode
类的实例,其中 item 是一个 NSTreeControllerTreeNode
。
到底是怎么回事? 根据所有文档和示例代码,我可以发现representedObject调用应该给我返回我在构建树时塞入NSTreeNode的NodeData
对象。
完全无能为力,因为我似乎是唯一的人遇到这个问题,所以我一定在某个地方做了一些非常愚蠢的事情 - 但我看不出代码有什么问题。
使用 setContent:[dataSourcesillyHack]
以编程方式填充树控制器 这个琐碎的内容显示了相同的行为:
- (NSMutableArray *) sillyHack
{
NSMutableArray *nodeArray = [NSMutableArray array];
NodeData *scaleTypeListNode = [[NodeData alloc] initWithName:@"123"];
NSTreeNode *scaleTypeListTreeNode = [NSTreeNode treeNodeWithRepresentedObject:scaleTypeListNode];
[scaleTypeListNode release];
[nodeArray addObject:scaleTypeListTreeNode];
return nodeArray;
}
任何帮助表示赞赏。
I'm setting up a NSOutlineView bound to a NSTreeController that's populated with NSTreeNode
instances, the latter having my custom NodeData objects attached using [NSTreeNode treeNodeWithRepresentedObject:...]
.
The outline view renders just fine, all data's there as expected, all good.
Now in the outline view's delegate I'm trying to change the render style via aoutlineView:willDisplayCell:forTableColumn:item:
method.
However, the item
parameter will not give me back my custom data!
id stuff = [item representedObject];
yields an instance of class NSTreeNode
where item is a NSTreeControllerTreeNode
.
What the heck is going on?
According to all documentation and sample code I could find the representedObject call should give me the NodeData
object back I've stuffed into the NSTreeNode when building the tree..
Totally clueless as I seem to be the only person having this problem so I must be doing something really stupid somewhere - but I can't see what's wrong with the code.
Populating the tree controller programmatically using setContent:[dataSource sillyHack]
with this trivial content shows the same behavior:
- (NSMutableArray *) sillyHack
{
NSMutableArray *nodeArray = [NSMutableArray array];
NodeData *scaleTypeListNode = [[NodeData alloc] initWithName:@"123"];
NSTreeNode *scaleTypeListTreeNode = [NSTreeNode treeNodeWithRepresentedObject:scaleTypeListNode];
[scaleTypeListNode release];
[nodeArray addObject:scaleTypeListTreeNode];
return nodeArray;
}
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用您自己的数据实例填充 NSTreeController,而不是 NSTreeNode。
You should populate NSTreeController with you own data instances, not NSTreeNode.