Re: NSTableView text color question
Re: NSTableView text color question
- Subject: Re: NSTableView text color question
- From: Laurent Daudelin <email@hidden>
- Date: Wed, 01 Oct 2003 09:35:07 -0400
on 01/10/03 08:18, Mike Brinkman at email@hidden wrote:
>
I tried removing the for loop, and it still doesn't work. Somehow, I need to
>
be able to tell the table view "if field x in row y is less than z, then
>
make the text red."
>
>
Does anybody here know how to do this? I was reading through the archives,
>
and somebody said they had an example, but I went to their .mac link and it
>
was gone. Could somebody PLEASE either provide a link to a sample that does
>
this, or simply tell me the exact 2 or 3 lines of code that I need to make
>
this work?
>
>
I'm begging, this is driving me NUTS!
>
>
>
On 9/29/03 9:47 PM, "Laurent Daudelin" <email@hidden> wrote:
>
>
> 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.
>
>
>
> 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.
I think the problem is that you don't seem to check what the toDo array
index is or what the toDo array contains at the index you're looping, thus
all rows appear in the same color. You always do a comparison reading the
value from this dueDateField, but when you're looping through the toDo
array, that value is likely always the same, so your test condition (if days
< 7) will always be true or false. Or I'm missing something...
-Laurent.
--
============================================================================
Laurent Daudelin AIM/iChat: LaurentDaudelin <
http://nemesys.dyndns.org>
Logiciels Nemesys Software
mailto:email@hidden
flamage /flay'm*j/ n.: [very common] Flaming verbiage, esp. high-noise,
low-signal postings to Usenet or other electronic fora. Often in the phrase
`the usual flamage'. `Flaming' is the act itself; `flamage' the content; a
`flame' is a single flaming message. See flame, also dahmum.
_______________________________________________
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.