Want an NSTableView with total row!

brianleahy

Colonel Panic
I'm writing a program in Cocoa, and I want to produce the effect of a last row in an NSTableView that will display totals of the numeric columns in the remainder of the view.

It'd be relatively easy to have it appear as the last line below the regular data, but that's not what I want.

In essence, I want something like an NSTableHeaderView that will sit at the bottom of the view, scroll horizontally but never vertically, and display the totals.

The approach I am trying is this: I've created a second NSTableView, only 1 row tall, and parked it underneath the main NSTableView. I turn OFF the horizontal scroller for the "mainView", and turn ON the horizontal scroller for the "totalView". It looks good, and displays the totals -- but now I want the totalView's horizontal scroller to control the horizontal scrolling of BOTH views.

Alas, the NSTableView class does not seem to have methods to access its horizontal scroller.

Can anyone suggest a solution? Or a whole new approach? Pleeze?
 
Well, that's because the NSTableView is inside the scroller, and doesn't own it. It's the other way around. You can get a pointer to the NSScrollView with [self enclosingScrollView] (it's a NSView method that NSTableView inherits).

If the second NSTableView is also in its own NSScrollView, you may be able to listen for -viewBoundsChanged and -viewFrameChanged notifications from the first NSTableView - but I'm not all that sure about that. NSScrollView doesn't seem to have any notifications or delegate methods to tell you directly that it scrolled.

An alternative you may look at is using a NSSplitView to show both tables. I believe there are some delegate methods you can use that would stop someone from resizing the splitview to show more than the header of the second tableview.
 
Back
Top