2012-03-16 36 views
4

在仔细阅读文档后,我发现没有合理简单的方法获得NSOutlineViewNSTreeController中对象的索引路径。因此,当我需要做某些需要它们的事情时(例如从树中删除特定的项目),我最终编写了非常难看的代码,试图自己组装索引路径。干净的方式来获取NSTreeController或NSOutlineView中的对象的NSIndexPath?

难道没有比[[NSIndexPath indexPathWithIndex:<blah>] indexPathByAddingIndex: <blah>]更好的方法吗?

回答

2

您可以轻松地构建像这样的路径:

NSUInteger indexes[4] = {2, 3, 1, 0}; 
NSIndexPath* path = [NSIndexPath indexPathWithIndexes:indexes length:4]; 

要获得一个特定模型对象的索引路径,看看my answer to this question

+2

'[_treeController.arrangedObjects descendantNodeAtIndexPath:[NSIndexPath indexPathWithIndex:[someOutline selectedRow]]]'必须是我曾经目睹_The grossest_构建体/一个API_的_bungles之一。苹果应该对自己感到羞耻。 – 2013-10-26 03:47:44

+1

Correctamundo。一般来说'NSTreeController'不是Apple最好的时间。 – 2013-10-28 00:29:02

+1

等等,更糟糕的是,仅仅为了得到突出显示的节点在“Tree Controlled”情况下的“值”需要.. [[[[_treeController.arrangedObjects descendantNodeAtIndexPath:[NSIndexPath indexPathWithIndex:[sender selectedRow]]] representObject] representObject]'Lol。那双double'representObject' _驱动我bananas_!这就像他们在破解...“嘿,让我们把它称为'objectValue'”,“不,我说'representObject',whhaaa!” ...“如何'selectionIndexes'”,“否'selectedIndexPath'”,“否,'NSOutlineViewSelectedPathIndexesPathBindingOption'!这是一个伟大的圆环。”哈! – 2013-10-30 08:30:47

相关问题