Re: Color entire table view row
Re: Color entire table view row
- Subject: Re: Color entire table view row
- From: David Remahl <email@hidden>
- Date: Fri, 05 Apr 2002 15:55:25 +0200
>
David,
>
>
On 4/5/02 2:33am, "David Remahl" <email@hidden> wrote:
>
> Before I read your original post:
>
> @interface NSCell(NSCellAttributedStringMethods)
>
> - (NSAttributedString *)attributedStringValue;
>
> - (void)setAttributedStringValue:(NSAttributedString *)obj;
>
>
Snip
>
>
Well... That doesn't really cut it. I don't care about attributed strings
>
and it still doesn't let me set the color value of text for the entire row.
>
I have one object in the data source that corresponds to a column in the
>
table and it IS an attributed string and it IS colored.
>
>
The whole point was to easily take that color and color the rest of the ROW
>
that it's in, so then I could have a green row (the text, not the bgcolor,
>
yuck), a red row, a grey row, a green row, another green row, a black row...
>
Etc.
>
>
In short, given the responses, it seems my original hypothesis that there's
>
no elegant way to do this is in fact true (at least to the extent of
>
"elegant").
Well, what is not elegant in using the data source and setting the
properties of the cell each time? That is the way things are normally done.
If you want to use proper MVC, have a model data storage and a controller
that combines the data with your interpretation of it (the colour).
>
Something like this as a table view delegate would be awfully nice:
>
- (NSDictionary *)displayAttributesForRow:(int)row
>
>
But oh well. :P
That is virtually what you have in the current implementation. This is what
would cause excess maintainance, if Apple would implement it, duplicating
already good code. But do feel free to file a feature request :-)
>
> After I read your initial post:
>
>
>
> Your task seems better fit for a formatter, don't you think? You will have
>
> to implement the formatter calling yourself from your datasource still, and
>
> still set the attributed string, but the final solution will be a bit more
>
> portable and encapsulated in a familiar interface.
>
>
Still too much work and still not elegant. This is one of those features
>
where "I'd implement it in my app if it exists, but it's not worth the time
>
or effort to write my own (and then be forced to maintain it)." I'm just
>
surprised that there's no method like the one I listed above.
>
Hmm, I tell you, you would never, ever, never have the patience to write
even the smallest carbon application...
What kind of method are you expecting? A [yourCell setTextColor:col]? That
_is_ exactly what the attributed strings are there for. Do you expect the
class to ignore color information in the attributed string if the color was
explicitly set, or should attributedness never use the explicit color?
Secondly, because the same cell is reused for each row, you would still have
to set the colour information in your data source delegate method.
/ David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.