views:

15

answers:

1

I want to display a grid of data, with long header names for the columns and long header names for the rows, but just a small amount of data in the cells, and I would like to do so in a compact manner, something sort of like this:

            V   V   V   V   V   V

            H   H   H   H   H   H
            e   e   e   e   e   e
            a   a   a   a   a   a
            d   d   d   d   d   d
            e   e   e   e   e   e
            r   r   r   r   r   r

            1   2   3   4   5   6
          -------------------------
H Header 1 | X |   | X | X |   | X |
H Header 2 | X |   | X | X | X | X |
H Header 3 | X |   |   |   |   | X |
H Header 4 |   | X | X |   |   | X |
H Header 5 |   |   | X | X |   |   |
H Header 6 | X | X |   | X |   | X |
          -------------------------

What makes sense to me, using Cocoa, is to use an NSTableView, but it is not clear to me that it is possible to do so (and I'm not adept enough to even know where to begin to subclass the column headers to hack it to do this).

Is there a nice way to do something like this in Cocoa for the Mac?

+1  A: 

There is no easier way than to provide custom NSTableHeaderView, NSTableColumnHeader, and NSTableHeaderCell subclasses. You'll also probably want to create a custom cell to handle drawing your first column (which will be your row header column) in a visually distinctive way.

Additionally, it's up to you to translate your data to the desired orientation, providing the row header for column 0 and the actual data for subsequent columns.

Joshua Nozzi
Wow. That's a shame, as I'm working on a small, internal, one-off application and that sounds like more effort than is warranted. Thanks for the answer.
Clinton Blackmore
NSTableView and friends were actually pretty well-engineered to act together as a flexible but very fast control. The whole thing, however, is in need of a full modern refresh (probably as a separate control geared toward smaller but more custom tables). I had to really dive in to tailor the UI of my XTabulator app. Not a fun thing to do.
Joshua Nozzi