Re: Color/Number List
Re: Color/Number List
- Subject: Re: Color/Number List
- From: Tom Waters <email@hidden>
- Date: Wed, 25 Jul 2001 19:49:07 -0700
On Wednesday, July 25, 2001, at 04:26 PM, Joshua D. Orr wrote:
I have a list (actually an array) of NSNumber's and NSColor's. The
colors
correspond to the numbers. I want to be able to somehow display these
in a
list (like a table). I am thinking about using a table and set the
textview
cells with the number, and somehow set the background color of the
textview
cells to the corresponding colors.
Is there someway to do this (I have been looking though the
documentation,
but have not found a way to do this), or is there some better way to do
this?
This is written in email and not tested... but it should point you in
the right direction.
assumes that your arrays are allocated and filled somewhere else...
it also assumes you have one column in your table and that that columns
dataCell prototype is an NSTextFieldCell
and that you've set the instance of MyDelegate as the table's dataSource
and delegate in IB.
@interface MyDelegate : NSObject
{
NSArray *numbers;
NSArray *colors;
}
@end
@implementation MyDelegate
- (void)tableView:(NSTableView *)view
willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)col
row:(int)row
{
[cell setBackgroundColor: [colors objectAtIndex:row]];
}
- (int)numberOfRowsInTableView:(NSTableView *)view
{
return [numbers count];
}
- (id)tableView:(NSTableView *)view
objectValueForTableColumn:(NSTableColumn *)col
row:(int)row
{
return [numbers objectAtIndex:row];
}
@end