Objective c 在NSTreeController或NSOutlineView中获取对象NSIndexPath的干净方法?
仔细阅读文档后,我发现在Objective c 在NSTreeController或NSOutlineView中获取对象NSIndexPath的干净方法?,objective-c,macos,cocoa,nsoutlineview,nstreecontroller,Objective C,Macos,Cocoa,Nsoutlineview,Nstreecontroller,仔细阅读文档后,我发现在NSOutlineView或绑定到的NSTreeController中找不到一种相当简单的方法来获取对象的索引路径。结果,每当我需要做一些需要索引路径的事情时(例如,从树中删除特定项),我就编写了非常难看的代码,试图自己组装索引路径 没有比[[NSIndexPath indexPathWithIndex:]indexPathByAddingIndex:][/code>更好的方法了吗?您可以轻松构建如下路径: NSUInteger indexes[4] = {2, 3, 1
NSOutlineView
或绑定到的NSTreeController
中找不到一种相当简单的方法来获取对象的索引路径。结果,每当我需要做一些需要索引路径的事情时(例如,从树中删除特定项),我就编写了非常难看的代码,试图自己组装索引路径
没有比
[[NSIndexPath indexPathWithIndex:]indexPathByAddingIndex:][/code>更好的方法了吗?您可以轻松构建如下路径:
NSUInteger indexes[4] = {2, 3, 1, 0};
NSIndexPath* path = [NSIndexPath indexPathWithIndexes:indexes length:4];
要获取特定模型对象的索引路径,请查看。[\u treeController.arrangedObjects后代nodeatIndexXPath:[NSIndexPath indexPathWithIndex:[someOutline selectedRow]]]]
必须是我见过的API中最粗俗的构造/错误之一。苹果应该为自己感到羞耻NSTreeController
一般来说,这不是苹果最好的时刻。等等,更糟。。仅在“树控制”情况下获取高亮显示节点的“值”需要<代码>[[[u treeController.arrangedObjects-genderantnodeatIndeXPath:[NSIndexPath-indexPathWithIndex:[sender selectedRow]]]representedObject]representedObject]
Lol。这个双重representedObject
让我抓狂!就像他们在裂缝上一样。。。“嘿,让我们称之为objectValue
”,“不,我说representedObject
,whhaaa!”。。。“关于selectionIndexes
”、“NoselectedIndexPath
”、“No,NSOutlineViewsSelectedPathIndexeSpathBindingOption
”、“No,NSOutlineViewSelectedPathIndexesPathBindingOption
!这是一个很棒的环。”哈!链接答案仅适用于NSTreeController
NSOutlineView或数据源的解决方案是什么?