Clinton Blackmore
Clinton Blackmore

Reputation: 2497

Using an NSTableView as a grid, possibly with vertical labels?

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?

Upvotes: 0

Views: 519

Answers (1)

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

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.

Upvotes: 1

Related Questions