Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在NSTreeController或NSOutlineView中获取对象NSIndexPath的干净方法?_Objective C_Macos_Cocoa_Nsoutlineview_Nstreecontroller - Fatal编程技术网

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
”、“No
selectedIndexPath
”、“No,
NSOutlineViewsSelectedPathIndexeSpathBindingOption
”、“No,
NSOutlineViewSelectedPathIndexesPathBindingOption
!这是一个很棒的环。”哈!链接答案仅适用于
NSTreeController
NSOutlineView或数据源的解决方案是什么?