• 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
Re: Color/Number List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Color/Number List
      • From: "Joshua D. Orr" <email@hidden>
References: 
 >Color/Number List (From: "Joshua D. Orr" <email@hidden>)

  • Prev by Date: How is @selector resolved at compile time ?
  • Next by Date: Re: How is @selector resolved at compile time ?
  • Previous by thread: Color/Number List
  • Next by thread: Re: Color/Number List
  • Index(es):
    • Date
    • Thread