1
votes

OK. I looked through the suggestions (which often answer my questions before I ask). I haven't found what I need.

I know that I'm doing something wrong. I do this all the time in iOS (UIKit), but tables in NS (Mac) are pretty darn different from UIKit.

I have a view-based NSTableView. Each row has exactly 1 column. This column has a view with a header (21 points high), and an expanded view (the row is 420 points high). There is a disclosure triangle on the left of the header that toggles these two modes.

The controller is also the table datasource and delegate. I have the row height callback returning the correct values for the view.

The header displays fine. I set the row heights to 21, and only the headers are shown. This clips the main view.

A row of closed headers

When a disclosure triangle is toggled, a row expands its height to reveal the entire view:

An open row

Simple enough, eh?

The problem is that B is not displayed. I just get a blank (However, A is correctly displayed). The items are there, just not being displayed. The table row is the correct height (this can be verified by using alternating row colors).

I've tried setting setNeedsLayout/Draw on the views.

Any clues on what I may be doing wrong?

I'm willing to bet that I'm doing something boneheaded, and I'll keep looking into this.

1

1 Answers

1
votes

Using noteHeighOfRowsWithIndexesChanged:? It's an NSTableView function, not a delegate function.

In the documentation for the delegate function tableView:heightOfRow it declares:

Although table views may cache the returned values, you should ensure that this method is efficient. When you change a row's height you must invalidate the existing row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView automatically invalidates its entire row height cache when reloadData and noteNumberOfRowsChanged are called.

As it mentions, NSTableView's reloadData is often the lazy way to fix your sort of issue as well.

Your table controller shouldn't need the setsNeeds[whatever] methods you tried.

Also, speaking of disclosure triangles and such, on OSX there is a NSTableView subclass called NSOutlineView that handles item expansion if you mangle your data into a poorly documented tree format. I actually wouldn't recommend it if your data's not a natural tree, but you should be aware of it, even if its API sucks. Oh, and the expansion when clicking the disclosure triangle is animated.