NSFormatter and attributed strings
NSFormatter and attributed strings
- Subject: NSFormatter and attributed strings
- From: John Timmer <email@hidden>
- Date: Tue, 09 Oct 2001 13:04:39 -0400
Greetings -
I've tried to RTFM on this, but it's just causing me a headache (I think I'm
detecting circular references within the docs). I'll try for clarification
by suggesting a simple example from the docs themselves: let's say I want
an NSTableView to display positive numbers in black, negative in red. There
seem to be three methods I need to override:
public Object objectValueForString(String aString)
public String stringForObjectValue(Object anObject)
and
public NSAttributedString attributedStringForObjectValue( Object anObject,
NSDictionary attributes)
When the TableView attempts to show some text, which method is actually
called? What order are these methods called in? Which of these methods
should call one of the others (this is where the circularity of the docs
drove me nuts)? What class are the objects that are actually passed to
these methods?
The second aspect I don't quite understand is how to generate attributed
strings. I can figure out that I want to change the
ForegroundColorAttributeName in the attribute NSDictionary. The only way I
can see to do this is to create a generic attributed string, pull the
dictionary out of that by passing it null for its NSRange argument in
attributesAtIndex( int index, NSMutableRange aRange), and initialize a
mutable dictionary with that. I could then change the NSColor (if I could
figure out what object to pass as the key...), and initialize a new
NSAttributed string with the result.
It seems to me there's gotta be a better way.
Any advice or pointers to example code would be greatly appreciated.
Thanks,
Jay