• 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
NSFormatter and text color
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSFormatter and text color


  • Subject: NSFormatter and text color
  • From: patrick machielse <email@hidden>
  • Date: Mon, 4 Sep 2006 19:08:08 +0200

I have an outline view, and I want to change the text in some rows, depending on a certain conditions. For that puropose, I use the following code:

- (void)outlineView:(NSOutlineView *)outlineView
willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn
item:(id)item
{
// some items should have gray text color
if ( condition ) {
NSMutableAttributedString *maString;
maString = [[NSMutableAttributedString alloc] initWithAttributedString:[cell attributedStringValue]];
[maString addAttribute:NSForegroundColorAttributeName
value:[NSColor grayColor]
range:NSMakeRange(0, [maString length])];
[cell setAttributedStringValue:maString];
[maString release];
}


This works fine, _except_ when the cell has a formatter attached. In that case the NSFormatter method

- (NSAttributedString *)attributedStringForObjectValue:(id)obj withDefaultAttributes:(NSDictionary *)attrs

is called after outlineView:willDisplayCell:... , and the text styling (or at least the foreground color) is lost.

I have solved this by creating a custom formatter, but it is still unsatisfying solution. I guess I must be using the wrong approach here. If not I don't understand:

1) why the formatter is called _after_ 'willDisplay'
2) why the formatter doesn't preserve the styling of the text as much as possible
3) where the withDefaultAttributes: attributes dictionary comes from


what am I missing?

patrick
_______________________________________________
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


  • Prev by Date: Re: NSSlider unusual behavior
  • Next by Date: Re: Re: NSSlider unusual behavior
  • Previous by thread: Re: Dealloc NSMutableArray
  • Next by thread: Multiple drags joined in one undo group
  • Index(es):
    • Date
    • Thread