Re: SelectedRowIndexes
Re: SelectedRowIndexes
- Subject: Re: SelectedRowIndexes
- From: "I. Savant" <email@hidden>
- Date: Wed, 14 Oct 2009 12:11:39 -0400
On Oct 14, 2009, at 11:55 AM, gMail.com wrote:
Oh, come on, at least pick a witty pseudonym. :-D
when I call [tableView selectedRowIndexes];
I always get a indexSet already sorted by row.
Instead I need to sort it as the selection order.
I mean, if the user selected the rows in the order
Row 6
Row 2
Row 8
I want to get 6, 2, 8 and not 2, 6, 8 as I get now with
selectedRowIndexes.
How can I do that?
You can't. Not with -selectedRowIndexes. As you said, it returns an
NSIndexSet. Sets are unordered by nature. Not in the sense you're
looking for. They're kept internally as an ascending-order list for
efficiency.
You're going to have to track changes in selection yourself
(examine the NSTableView API - there are methods to help you with this).
Also consider a few scenarios that will affect "the selection order":
1 - Click the third row, shift-click the seventh row. Now the
selection index set is now {2, 3, 4, 5, 6}.
2 - With that last result, command-click row 3, then, 4, then 3 again.
The selection set is now {2, 3, 5, 6}.
3 - Click row 7, shift-click row 6, then Cmd-click row 8. Selection is
now {5, 6, 7}.
Considering these scenarios, what would your selection order be in
each? What about combining them? Selection can go in many directions
and things can be added and removed to/from anywhere in the set. Think
carefully - getting this basic behavior wrong has the potential to
annoy users.
Please note that I can select the rows even programmatically,
because the
user selects an object on the canvas.
Same as above - you'll have to track the order. I'd make a table
view subclass and override (calling super, then my custom code) the
selection-changing methods, then provide a separate selection-getting
routine (to provide an ordered array of indexes) called
"orderedSelection" or something similar. This gives you one central
place for user- or code-initiated selection changes.
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden