Re: Color/Number List
Re: Color/Number List
- Subject: Re: Color/Number List
- From: "Joshua D. Orr" <email@hidden>
- Date: Thu, 26 Jul 2001 22:56:42 -0600
It does not appear to work, the cells do not change to the correct color
(but the numbers do get displayed). Does anyone have any idea what's
wrong?
On Wednesday, July 25, 2001, at 08:49 PM, Tom Waters wrote:
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
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev