Hi, All,

I'm trying to color my table's rows depending on some value, returning from a function like this:

int GetState(int rowIndex);

I've searched around the Net and the only clear way I've found is to set my AppController, as a tableView delegate and respond to the message

- (void)tableView:(NSTableView *)aTableView
  willDisplayCell:(id)aCell
   forTableColumn:(NSTableColumn *)aTableColumn
                          row:(int)rowIndex;

I've created this method as the next:

        if (rowIndex == selRow)
                color = [NSColor selectedTextColor];
        else
        switch (st = GetState(rowIndex)) {
                case 1 : { color = [NSColor colorWithCalibratedRed:0
                                                                                
                         green:0
                                                                                
                          blue:0.5
                                                                                
                         alpha:1.0]; break; }
                case 2 : { color = [NSColor colorWithCalibratedRed:0
                                                                                
                         green:0.5
                                                                                
                          blue:0
                                                                                
                         alpha:1.0]; break; }
                case 3 : { color = [NSColor colorWithCalibratedRed:0.5
                                                                                
                         green:0
                                                                                
                          blue:0
                                                                                
                         alpha:1.0]; break; }
        }
        [aCell  setTextColor:color];

I've got a strange effect: a new row is selected OK, when I change selection in the tableview, but the row, which was selected, remains being drawn with the same selected color unless reloadData will appear. Therefore, changing selection quickly I can change color of many rows to selected color, unless update will come. Selection bar itself looks OK, and selected row background and text color changes immediately, but how to update the row, which was previously selected? I believed it will be done by my delegate method. It looks like this method is called at some not appropriate time. Is there a solution?

Thanks.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to