2012-03-16 74 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

相關問題