cocoapyobjc

How to get selected item of NSOutlineView without using NSTreeController?


How do I get the selected item of an NSOutlineView with using my own data source. I see I can get selectedRow but it returns a row ID relative to the state of the outline. The only way to do it is to track the expanded collapsed state of the items, but that seems ridiculous.

I was hoping for something like:

array = [outlineViewOutlet selectedItems];

I looked at the other similar questions, they dont seem to answer the question.


Solution

  • NSOutlineView inherits from NSTableView, so you get nice methods such as selectedRow:

    id selectedItem = [outlineView itemAtRow:[outlineView selectedRow]];