Re: Sorting columns of non-reorderable columns tableview
Re: Sorting columns of non-reorderable columns tableview
- Subject: Re: Sorting columns of non-reorderable columns tableview
- From: John Hansen <email@hidden>
- Date: Fri, 07 Sep 2001 09:44:03 -0700
Thanks but...
1. I don't want the user to be able to reorder the columns!! ( This should
not stop me from receiving a notice that a column header has been clicked!
bad assumption on class designers part!)
2. In the sample code that is shown table header cell is replaced, but not
initted with the right values from the old header cell that was initted by
the nib file.
What I need is something more like.
unsigned i, count;
NSArray *tableColumns = [tableView tableColumns];
for (i = 0, count = [tableColumns count]; i < count; i++) {
NSTableColumn *aTableColumn = [tableColumns objectAtIndex:i];
MyTableHeaderCell *tableHeaderCell;
tableHeaderCell = [[MyTableHeaderCell alloc] initTextCell:@""];
/*
copy all the needed info from old header cell from each field foo
*/
{
[ tableHeaderCell setfoo: [aTableColumn headerCell] foo ];
...
}
[aTableColumn setHeaderCell:tableHeaderCell];
[tableHeaderCell release];
}
But I don't know what is the correct info!!!
JH
>
From: Jean-Michel Vallat <email@hidden>
>
Date: Fri, 07 Sep 2001 09:13:21 +0200
>
To: John Hansen <email@hidden>
>
Subject: Re: Sorting columns of non-reorderable columns tableview
>
>
>
>
> 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
>
>
Inspect your tableView with IB, and select the "Allows Reordering" check
>
box...
>
>
> then tableView:didClickTableColumn is never called
>
>
... then, this method will be send to the TV delegate when needed.
>
>
>
> 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.
>
>
You're right: in order to draw a "sort indicator flag", you'll need to
>
subclass NSTableHeaderCell and override -[drawInteriorWithFrame:inView:] or
>
-[drawWithFrame:inView:].
>
>
And the only way to replace the default HeaderCell of a TV is to do it
>
programmatically.
>
Example:
>
>
unsigned i, count;
>
NSArray *tableColumns = [tableView tableColumns];
>
>
for (i = 0, count = [tableColumns count]; i < count; i++) {
>
NSTableColumn *aTableColumn = [tableColumns objectAtIndex:i];
>
MyTableHeaderCell *tableHeaderCell;
>
>
tableHeaderCell = [[MyTableHeaderCell alloc] initTextCell:@""];
>
[tableColumn setHeaderCell:tableHeaderCell];
>
[tableHeaderCell release];
>
}
>
>
>
>
> [...]
>
>
> Please give some help
>
> John Hansen
>
>
>
Jean-Michel
>
--