Sorting columns of non-reorderable columns tableview
Sorting columns of non-reorderable columns tableview
- Subject: Sorting columns of non-reorderable columns tableview
- From: John Hansen <email@hidden>
- Date: Thu, 06 Sep 2001 11:11:01 -0700
Help...
I would like to be able to sort by column a table view which does not allow
column reordering. Using NSArray functions to do the sorting is the easy
part. BUT HOW DO I GET THE CORRECT BEHAVIOR OUT OF NSTableView.
The type of behavior I want is like the Finder list view.
1. Click on a column header and it tracks the mouse click becoming darker
as the cursor enters and the column header and back to normal if the cursor
leaves.
2. If the mouse up occurs in the column header the table is sorted by that
column and an indicator states which direction the sort is in. If the table
was already sorted by that column, the directon of the sort is toggled.
3. If the mouse up occurs outside the column header nothing happens.
This is a good UI and since the Finder uses it, it will probably be
expected.
It seems that there are roadblocks at every turn when trying to do this in
cocoa - but it may be that I just don't know how to do things correctly yet.
First of all - it seems that if the columns are not allowed to be reordered
then
tableView:didClickTableColumn is never called the only call to the delegate
is
tableView:mouseDownInHeaderOfTableColumn - which only allows me to do
actions on mouse down.
I tried the obvious way of subclassing NSTableHeaderCell - but can't find a
way to get InterfaceBuilder to use my custom class for the cell.
I tried subclassing NSTableColumn and using IB to set it as the custom class
for each column. Then I was going to programattically allocate an instance
of my new headerCell type and replace the default NSTableHeaderCell using
setHeaderCell, but this meant trying to assign all relevant fields that were
assigned by IB to the instance of NSTableHeaderCell. Isn't there a way to
get NSTableView to use a subclass of NSTableHeaderCell!!!!
Please give some help
John Hansen