 |
 |
NSTableView row coloring example
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
Because this seems like a frequently requested feature, I dove in and put together an NSTableView subclass that you all may download.
It's available with an example of how to use it at:
<a href="http://homepage.mac.com/sapphire/FileSharing1.html" target="_blank">http://homepage.mac.com/sapphire/FileSharing1.html</a>
Features include:
• the simple 'iTunes-like' alternate row coloring (with row coloring even in the grid areas) with no pesky white spaces, plus settable highlight coloring for selected rows.
• the tricky column resizing & horizontal scrolling that could come up (that was a big pain in the butt - I had to subclass NSTableHeaderView and override the mouseDown).
• as a bonus, you can add the optional method to your dataSource - (NSColor *) tableView: (NSTableView *)tableView backgroundColorForRow: (int) row; which will let you set the background color for any specific row
• similarly, you can add the optional method to your dataSource - (NSColor *) tableView: (NSTableView *)tableView highlightColorForRow: (int) row; to set the highlight colors too, so you can make it real, um, artistic
• some preset colors
This will also work with any kind of cells in your columns as long as they respond to setBackgroundColor: (which popup menus do, fortunately, in my case)
To use this in your project, all you need to do is:
• add the ColoredRowTableView.h & ColoredRowTableView.m files to your project
• add the outlet variable to your controller of type ColoredRowTableView
• add the header file to your nib and set the NSTableViews custom class to ColoredRowTableView, set your dataSource to your controller, and put in the awakeFromNib:
[coloredTV setOddRowColor:[ColoredRowTableView paleBlue]];
[coloredTV setHighlightColor:[ColoredRowTableView paleHighlightBlue]];
• set your table view in the nib to be your new outlet variable
Pretty much, if you know how to set up an NSTableView, you should have no problems converting it to a ColoredRowTableView.
Enjoy! 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Oct 2001
Status:
Offline
|
|
I downloaded the example project but the project doesn't open in PB. Im used to seeing projects with the extension .pbproj while this one has extension .pbxproj. what is the difference?
Since I cant run the project, I'm not sure if it has small gray column dividers. Does it? I hope so.
feature request- option clicking the table column header resizes that column to width of widest cell in column. (but no smaller than minimum column width)
|
3R1C
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
oops- looks like stuffit changed the name of the .pbproj folder (maybe the name was too long?).
Change the ColoredRowTableViewExample#F54A folder to ColoredRowTableViewExample.pbproj and all should be well
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
oh, and yes it does handle your gray separators- just turn on the drawsGrid (checkbox in Interface Builder for TableViews or using the , and choose the color- my example shows a red grid) - setDrawsGrid: method.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by 3R1C:
<strong>feature request- option clicking the table column header resizes that column to width of widest cell in column. (but no smaller than minimum column width)</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Since the dataSource takes care of the data, I recommend that a notification is posted and that your dataSource registers for it. Also, I recommend that it be a double-click vs. option clicking. So add something like:
if ([theEvent clickCount]==2) {
NSNotificationCenter *center;
center = [NSNotificationCenter defaultCenter];
[center postNotificationName: @"TableViewColumnSeparatorDoubleClick" object: tv userInfo: col];
}
to the ColoredRowTableHeaderView mouseDown: method after the while loop. In your dataSource notification handler, go through your data and get the string size for whatever font you happen to be using. Of course this would only work with text cells! Maybe I'll look into doing it generically (for text cells)...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Oct 2001
Status:
Offline
|
|
Wow . thats fat dude! Maybe we could roll it into an IB palette? I have no idea how to do this but Im eager to try.
it could also use this:
[theTableView sizeLastColumnToFit];
|
3R1C
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
Thanks for the example Brad  I will try it really soon. But just out of curiosity... Do you work for Apple? (there were a few tipoffs...)
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong>Thanks for the example Brad  I will try it really soon. But just out of curiosity... Do you work for Apple? (there were a few tipoffs...)</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Busted <img border="0" title="" alt="[Eek!]" src="eek.gif" />
But don't let it make you think any more (or less?) of me! I'm still learning as I go.
Since the version I've put up on my downloads site, I've improved the class to also auto-resize columns to the max data length upon double-clicking the column separator, plus I may have fixed a couple of somewhat obscure bugs... if there is any demand in it, I'll post a new example.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Brad Brack:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong>Thanks for the example Brad  I will try it really soon. But just out of curiosity... Do you work for Apple? (there were a few tipoffs...)</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Busted <img border="0" title="" alt="[Eek!]" src="eek.gif" />
But don't let it make you think any more (or less?) of me! I'm still learning as I go.
Since the version I've put up on my downloads site, I've improved the class to also auto-resize columns to the max data length upon double-clicking the column separator, plus I may have fixed a couple of somewhat obscure bugs... if there is any demand in it, I'll post a new example.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Well it'll be a lot easier to start the thread "Brad is responsible for fuxxing up the alternating colors in iTunes!" bwahaha.. Um..
Next topic <img border="0" title="" alt="[Wink]" src="wink.gif" />
Is it possible that in your next version, which you will release... Well open up itunes.. And make the last column smaller. Notice that there is no white on the left. Rather there is a fake "empty" column that you can't mess with. Can you recreate that? I wish ALL table views would react like that. The white space just looks messy and ugly. Also.. is it just me or are your separator lines thicker than the normal ones? Or maybe they're blurry.. I dunno.. fix that <img border="0" title="" alt="[Wink]" src="wink.gif" />
Other than that.. it's work fine somewhat. I couldn't get it into my app, but I was able to put my app in your app.. I'll post more specific details later and you can help me do it the other way around  Seeing as I have about 60 outlets...
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif"><strong>Well it'll be a lot easier to start the thread "Brad is responsible for fuxxing up the alternating colors in iTunes!" bwahaha.. Um..
</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Whoa, now, before any of the rumors start, I need to nip that in the bud, I'm not affiliated with the iTunes team: this example is completely written independently of any development team and is an excercise of my own and should be treated as such... any code in that example has been written from scratch by me and is not a part of any publicly available software. I use it for some internal apps and utilities I've written and is meant as an example of how I accomplished this task- do not treat it as official bullet-proof code!
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif"><strong>
Next topic <img border="0" title="" alt="[Wink]" src="wink.gif" />
Is it possible that in your next version, which you will release... Well open up itunes.. And make the last column smaller. Notice that there is no white on the left. Rather there is a fake "empty" column that you can't mess with. Can you recreate that? I wish ALL table views would react like that. The white space just looks messy and ugly. Also.. is it just me or are your separator lines thicker than the normal ones? Or maybe they're blurry.. I dunno.. fix that <img border="0" title="" alt="[Wink]" src="wink.gif" />
</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">That shouldn't be too hard- I'll look into it (it may not need another column- just like filling in the colors beyond the last row doesn't require additional rows). Regarding the thickness/blurryness, that may be a function of the color or else it may be drawn twice... as I said it isn't a perfect example, but I'll look into it.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif"><strong>
Other than that.. it's work fine somewhat. I couldn't get it into my app, but I was able to put my app in your app.. I'll post more specific details later and you can help me do it the other way around  Seeing as I have about 60 outlets...</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Sure- I'll be glad to help you figure this out.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2001
Location: Seattle, WA
Status:
Offline
|
|
Just out of curiosity will this code ever become part of the official API, or as you said just some of your own stuff for personal use?
|
|
The spirit of resistance to government is so valuable on certain occasions, that I wish it always to be kept alive.
- Thomas Jefferson, 1787
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by juanvaldes:
<strong>Just out of curiosity will this code ever become part of the official API, or as you said just some of your own stuff for personal use?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">This was just a personal challenge for some internal work which the timing happened to coincide with a couple of posts asking how to do it.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
I get a home page not found error when trying the link. Can someone mirror it for me please...
Thanks.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|