Re: NSTableView text color question
Re: NSTableView text color question
- Subject: Re: NSTableView text color question
- From: Laurent Daudelin <email@hidden>
- Date: Mon, 29 Sep 2003 21:47:49 -0400
on 29/09/03 20:58, Mike Brinkman at email@hidden wrote:
>
I have a "To Do" application that I'm writing for the sake of learning. It's
>
nothing special, except that it allows me to challenge myself a little and
>
go beyond what I've read in the books I have.
>
>
The To Do app has a to-do item and a due date. This info is entered into a
>
form, and then is displayed in a table with two rows called "toDoItem" and
>
"dueDate". The table can be sorted by clicking in the header of each column.
>
>
I would like the table to display the text of a to-do item & due date in red
>
text. I looked through the archives and was directed to the following site:
>
>
http://www.cocoadev.com/index.pl?AlternatingRowColors
>
>
This went a long way to answering my question. Now I've got this code, which
>
will change the color of ALL rows, not just the rows which are close to due.
>
>
>
- (void)tableView: (NSTableView *)aTableView willDisplayCell: (id)aCell
>
forTableColumn: (NSTableColumn *)aTableColumn row: (int)aRowIndex
>
{
>
int i, days;
>
>
for (i = 0; i < [toDo count]; i++) // toDo is an NSMutableArray of
>
// to-do items
>
{
>
NSCalendarDate *today = [NSCalendarDate calendarDate];
>
NSCalendarDate *myDate = [NSCalendarDate
>
dateWithNaturalLanguageString:
>
[dueDateField stringValue]];
>
>
[myDate years:NULL months:NULL days:&days hours:NULL
>
minutes:NULL seconds:NULL sinceDate:today];
>
>
if (days < 7)
>
{
>
[aCell setTextColor:[NSColor redColor]];
>
}
>
else
>
{
>
[aCell setTextColor:[NSColor blackColor]];
>
}
>
}
>
}
>
>
Obviously that's not what I want. I can't quite figure out how to limit the
>
color change to only the appropriate row. I know aRowIndex has something to
>
do with it, but I'm really having a mental block. Any suggestions would be
>
greatly appreciated.
Hmmm, IIRC, the 'tableView:willDisplayCell:forTableColumn:row:' method will
be called repeatedly for each row. So, you don't need to loop through your
array, just use the row index to get the To Do that will be displayed and
set the text color appropriately.
-Laurent.
--
============================================================================
Laurent Daudelin AIM/iChat: LaurentDaudelin <
http://nemesys.dyndns.org>
Logiciels Nemesys Software
mailto:email@hidden
brain dump n.: [common] The act of telling someone everything one knows
about a particular topic or project. Typically used when someone is going to
let a new party maintain a piece of code. Conceptually analogous to an
operating system core dump in that it saves a lot of useful state before an
exit. "You'll have to give me a brain dump on FOOBAR before you start your
new job at HackerCorp." See core dump (sense 4). At Sun, this is also known
as `TOI' (transfer of information).
_______________________________________________
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.