NSTableView text color question
NSTableView text color question
- Subject: NSTableView text color question
- From: Mike Brinkman <email@hidden>
- Date: Mon, 29 Sep 2003 20:58:05 -0400
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.
_______________________________________________
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.