Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > tableView question

tableView question
Thread Tools
dws
Forum Regular
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Status: Offline
Reply With Quote
May 8, 2002, 04:47 PM
 
I have a program that I've written - an RTF journal writing application, with a drawer that contains previous journal entries in a tableView. Everything works beautifully, but I have a small problem whose solution completely eludes me. Perhaps one of you good people could lend an assist...

My tableView has three columns: Date, Title, Importance label (A-Z). The date is generated by the program, the title is input by the user in the save panel, and the importance label is a NSPopUPButton in the save panel - all are NSStrings; with the whole shebang saved on disk as a dictionary plist. Everything is quite standard and the information displays correctly.

The problem comes when I add a background color to the tableView. The journal entries are able to have user-specified colored text and background. I didn't want to monkey with the text color in the drawer's tableView, so I set the background color using:
[tableView setBackgroundColor:[backgroundColor highlightWithLevel:0.33]];
This creates a very nice affect. Even if the journal entry has a dark background color with light text, the tableView will display black text and a background color that is light enough to clearly see the text, but coordinates nicely with whatever background color is set for each particular journal entry being viewed.

Everything works exactly as it should - except the background color for the importance label column is always white!

I've tried many things to fix this. I've added more columns and they all have the desired background color. I've taken the offending column completely out and put it back in again - still white! The only thing that I haven't tried is to make everything an NSAttributedString and force the background color in that way; but I shouldn't have to do this.

I can't really think of any code to show you that might be problematic; though perhaps I'm making some stupid mistake in the tableView implementation::

- (int)numberOfRowsInTableView NSTableView *)aTableView
{
return [optedEntriesArray count];
}

- (id)tableView NSTableView *)aTableView objectValueForTableColumn NSTableColumn *)aTableColumn row int)rowIndex
{
return [[optedEntriesArray objectAtIndex:rowIndex] valueForKey:[aTableColumn identifier]];
}

- (void)tableView NSTableView *)aTableView setObjectValue id)anObject forTableColumn NSTableColumn *)aTableColumn row int)rowIndex
{
[[optedEntriesArray objectAtIndex:rowIndex] takeValue:anObject forKey:[aTableColumn identifier]];
[self saveAllEntriesArray]; // save any changes made to the Title or Importance Label
}

The application is finished. It has preferences, interface sounds, the ability to import rich text files, the ability to display multiple journal entries in one window, a nice search function, help & various options for displaying the previous entries list (display entries for the current month, the current year, or all entries - and a nice slider that dictates the line height displayed in the tableView); all wrapped up in a simple interface that is as intuitive to use as I could create. Even the icon I designed for it is pretty! The only thing stopping me from publishing it on VersionTracker is that darn white background to one lonely little letter! The issue is driving me nuts!!!

I've thought of just deleting the feature that's giving me problems. I wasn't even sure I wanted it in the first place, but a beta tester thought that it was the greatest thing since sliced bread (which I also don't like - too thin!). But deleting the importance label now would seem like defeat!

I feel that I'm making some simple mistake; so simple that I can't see the problem amidst all the other code - or - that that I have some basic lack of understanding on how information is displayed in a tableView.

I would greatly appreciate any thoughts you might have on my little problem.

Thanks,
dws
     
dws  (op)
Forum Regular
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Status: Offline
Reply With Quote
May 8, 2002, 04:49 PM
 
Sorry for all the frowning faces in my original post. I wasn't aware that "" would become a little icon! I should have disabled smilies.

dws
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
May 8, 2002, 05:25 PM
 
Unless the object value is an attribute string, I'm not sure why this is happening.

Get the dataCell for your label column... presumably this is an NSTextFieldCell? If so, call -setDrawsBackground:NO on it.

Something like this maybe in the delegate:
- (void)tableViewNSTableView *)tableView willDisplayCellid)cell forTableColumnNSTableColumn *)tableColumn rowint)row
{
if ([cell isKindOfClass:[NSTextFieldCell class]])
[cell setDrawsBackground:NO];
}

That's about the only thing I can think of. Not sure why it's not working for you now, unless you've changed the dataCell to something other than the default.
     
dws  (op)
Forum Regular
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Status: Offline
Reply With Quote
May 9, 2002, 01:12 PM
 
Thank you, lindberg, for your reply.

I tried your suggestion and it didn't work! In fact, it was never even called. Ah ha. This instantly led me to the real problem. One does have to assign a delegate correctly!

This leads to a short discussion on program design. Plan the whole thing before implementation! I took the typical 'start simple and add stuff as you go along' approach. This can easily cause problems when you try to make all the parts work together correctly.

Again, thank you.
dws
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:56 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2