Skip navigation.
 
mlRe: Correctly Subclassing NSTableHeaderCell?
FROM : Daniel Kennett
DATE : Fri Jan 04 12:41:15 2008

Thanks everyone for your help - I've figured it out:

- When detecting a mouse click, you should check [self state] rather 
than [self highlighted].

- Drawing the sort indicators needs more than is (easily) accessible 
inside the cell. So, the header cell gets this method:


-(void)setSortAscending:(BOOL)asc priority:(int)pri {
   sortPriority = pri;
   sortAscending = asc;
   
   [(NSControl *)[self controlView] updateCell: self];
}

... and in the drawing method:

-(void)drawWithFrame:(NSRect)frame inView:(NSView *)view {
   [...]
   [self drawSortIndicatorWithFrame:frame inView:view 
ascending:sortAscending priority:sortPriority];
}

... and finally, in the tableView's delegate (trackListController is 
an IBOutlet to the ArrayController that deals with the table's 
contents):

- (void)tableView:(NSTableView *)tableView didClickTableColumn:
(NSTableColumn *)tableColumn {
   [(KNTableHeader *)[tableColumn headerCell] setSortAscending:
[[[trackListController sortDescriptors] objectAtIndex:0] ascending] 
priority:0];
   // Loop through the other columns and set their priority to 1.
}

This gives the cell all the details it needs to draw the sort 
indicators properly. Hope this is helpful to someone!Thanks,

-- Daniel

  _______________________

    <email_removed>
    http://www.kennettnet.co.uk

Please include previous messages in any reply you send.


On 3 Jan 2008, at 16:33, Daniel Kennett wrote:

> Hey all,
>
> I'm trying to subclass NSTableHeaderCell to get a darker look, a'la 
> iTunes and iCal. I've got it drawing perfectly well and I'm happy 
> with the look, but I can't get it to highlight when clicked or is 
> the sorted column, and I can't get it to show the sort direction 
> indicator either.
>
> I've searched the docs and online, but can't seem to find anything. 
> Has anyone done this successfully?
>
> <Picture 2.png>

Related mailsAuthorDate
mlCorrectly Subclassing NSTableHeaderCell? Daniel Kennett Jan 3, 17:33
mlRe: Correctly Subclassing NSTableHeaderCell? I. Savant Jan 3, 17:37
mlRe: Correctly Subclassing NSTableHeaderCell? Daniel Kennett Jan 3, 17:58
mlRe: Correctly Subclassing NSTableHeaderCell? Steve Nygard Jan 3, 18:19
mlRe: Correctly Subclassing NSTableHeaderCell? Tommy Nordgren Jan 4, 01:33
mlRe: Correctly Subclassing NSTableHeaderCell? Daniel Kennett Jan 4, 12:41