• 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
Re: Advice on using NSCell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on using NSCell


  • Subject: Re: Advice on using NSCell
  • From: Keith Wilson <email@hidden>
  • Date: Fri, 3 Mar 2006 13:48:51 +1100

The only way I have found to do this is to use willDisplayCell as follows

-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)aTableColumn row:(int)row
{
if(row < 0)
return;
//NSParameterAssert((row >= 0) && (row < [array count]));
NSFontManager *fm = [NSFontManager sharedFontManager];
NSFont *font = [cell font];
if([array objectAtIndex:row] thing] == whatever) && [cell == ,,,,))
[cell setFont:[fm convertFont:font toHaveTrait:NSBoldFontMask]];
else if(......)
etc
etc
}


Keith from DownUnder

On 03/03/2006, at 11:47 AM, James Bucanek wrote:

Greetings,

I'm attacking yet-another-table in Cocoa, and I've run into a reoccurring problem.

I have an NSTableView of data. The different columns store different types of data values (dates, sizes, other abtstact stuff). I've created formatters for all of the non-numeric and non- string values and NSCell handles all of the details beutifully.

Now I need to add some global behaviour to all of my cells. I need to change the appearance of the text in every cell of a row based on some criteria: Specifically, I want to draw the text in grey if the row represents an empty data record.

I can't find any clean, well organized, way of doing this. I assume I need to test a value in the data record then create an NSDictionary of text attributes for drawing. But where/how do I insert those attributes?

- If I change my table data source to return NSAttributedStrings instead of the raw data objects, I defeat all of the formatters I just wrote to handle the conversion of object values to text. I also lose all of NSCell's alignment features for numeric values.

- If I subclass NSCell and override setObjectValue to intercept the value and call setAttributedStringValue instead, I have the same problem.

- If I subclass NSCell and override drawInteriorWithFrame:, I lose most of the advantages of using NSCell in the first place. Plus, I'll probably break something down the line if the behaviour of NSCell ever changes.

I keep thinking that there must be some aspect of the NSTable/ NSCell interface that I'm missing and that would allow me to add row-specific formatting to all cells without defeatings NSCell's formatter, alignment, and drawing routines.

--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40bigpond.net.au


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Advice on using NSCell
      • From: James Bucanek <email@hidden>
References: 
 >Advice on using NSCell (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Eval() ?
  • Next by Date: NSButton with modifier key
  • Previous by thread: Advice on using NSCell
  • Next by thread: Re: Advice on using NSCell
  • Index(es):
    • Date
    • Thread