Search code examples
nstableviewnssearchfield

NSTableView bound to NSSearchField - How to relate selection to unfiltered datasource


I'm stumped. My Swift app uses an NSTableView bound to an array controller, and uses a bound NSSearchField as a text filter. My problem is that the table's selectionIndexes binding gives me the selected indexes in the filtered table, whereas I need the selected indexes in the unfiltered table.

Example... my table has 1000 rows and I want to select row 567. Rather than scroll down to row 567, I enter a few characters into the search box, and this reduces the number of rows to 17, and the row I'm interested in is now row 12. If I select row 12, how can my app figure out that row 12 corresponds to row 567 in my data array?


Solution

  • selectionIndexes of NSArrayController are indexes in arrangedObjects of the arrayController. arrangedObjects is the content of the arrayController, filtered by filterPredicate and sorted by sortDescriptors.