Re: Correctly Subclassing NSTableHeaderCell?
Re: Correctly Subclassing NSTableHeaderCell?
- Subject: Re: Correctly Subclassing NSTableHeaderCell?
- From: Daniel Kennett <email@hidden>
- Date: Fri, 4 Jan 2008 11:41:15 +0000
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@hidden
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>
_______________________________________________
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