Reputation: 444
I want to implement a side bar working like Finder.app. But I have no idea how to make it keeping the row selected state after collapsing and expanding the group.
Any idea or suggestion will be appreciated.
Upvotes: 3
Views: 1283
Reputation: 2960
You will have to implement it yourself. The reason why system don't preserve the selection for you is that when an item is collapsed, all of its subitems are actually released, so they won't be exist at all.
The solution is pretty easy and straight-forward.
ivar
, and update it in response to user interaction. To do this, you may want to implement the -outlineViewSelectionDidChange:
delegate method. Note that you should always ensure that [[notification object] selectedRow] != -1
is satisfied before updating it, since collapsing the selected item will cause this message to be sent with a selectedRow
of -1
.-outlineViewItemDidExpand
delegate method, if outlineView.selectedRow
is -1
, consult your ivar
and manually resume the selection by sending a -selectRowIndexes:byExtendingSelection:
message to your NSOutlineView
.Upvotes: 8