• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Sortable Table Column with Custom Appearance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sortable Table Column with Custom Appearance


  • Subject: Sortable Table Column with Custom Appearance
  • From: Seth Willits <email@hidden>
  • Date: Tue, 22 Jan 2008 23:55:41 -0800

Aloha,


I'm trying to create a custom table view appearance, sort indicators and all, and I'm having a problem getting the sort indicator to draw at all.


It seems that NSTableHeaderCell doesn't actually draw the sort indicator when calling drawSortIndicatorWithFrame:..., at least if I call it from within my drawInteriorWithFrame:... method then it doesn't actually show up. I am noticing that if I don't override highlight:withFrame:inView: then the sort indicator draws fine. The funny thing is that drawSortIndicatorWithFrame:... is not called from highlight:withFrame:inView:. So I can't figure out what I'm supposed to do to get the superclass to draw the indicator for me. Just figuring out whether or not it should draw one and in which direction is icky enough.

I'm looking for a better way to do what I'm doing, and some method of getting the sort indicator to draw (without having to grab an image and draw it myself). Here's what I'm doing:



- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
    ... draw normal background appearance ...
    [self drawInteriorWithFrame:cellFrame inView:controlView];
}


- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView: (NSView *)controlView;
{
... draw highlighted background appearance ...
[self drawInteriorWithFrame:cellFrame inView:controlView];
}




- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
... draw the column title ...



// Figure out which direction the sort indicator should be facing and draw it (if needed)


    BOOL ascending = YES;
    NSInteger priority = 1;

int columnIndex = [(NSTableHeaderView *)[self controlView] columnAtPoint:NSMakePoint(cellFrame.origin.x + 1.0, cellFrame.origin.y + 1.0)];
NSTableView * tableView = [(NSTableHeaderView *)[self controlView] tableView];
NSTableColumn * column = [[tableView tableColumns] objectAtIndex:columnIndex];


if (column == [[tableView tableColumns] objectAtIndex:[tableView selectedColumn]]) {
for (NSSortDescriptor * descriptor in [tableView sortDescriptors]) {
if ([[descriptor key] isEqual:[column identifier]]) {
priority = 0;
ascending = [descriptor ascending];
}
}


[self drawSortIndicatorWithFrame:cellFrame inView:controlView ascending:ascending priority:priority];
}
}





drawInteriorWithFrame:inView: is pretty ugly. :(



--
Seth Willits




_______________________________________________

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


  • Prev by Date: Re: [[NSView animator] setHidden:YES] doesn't fade?
  • Next by Date: Re: Understanding the inner workings: getting to know how functions are called
  • Previous by thread: re: Core Data Performance
  • Next by thread: How to with NSCollectionView?
  • Index(es):
    • Date
    • Thread