Repost: Summary row for scrolled TableView
Repost: Summary row for scrolled TableView
- Subject: Repost: Summary row for scrolled TableView
- From: Toby Sargeant <email@hidden>
- Date: Tue, 28 Jan 2003 12:02:52 +1100
Hi,
Sorry about the cross/repost, but I think that posting on the
weekend initially might have been a bad idea in terms of
getting responses.
[I'll combine the two posts]
I was wondering what the best way to implement a summary row
(e.g. a row at the bottom of the view of the table that scrolls
left and right, and shows per-column totals) for a TableView
would be.
I would have thought that this was a reasonably common mode
of use for tables, but I haven't been able to find any support
for or example code. ScrolledView Rulers seem to provide part
of the solution, but it appears that they are fixed to the top
and right sides of the ScrolledView, whereas I'm more interested
in bottom (and left).
The other alternatives I have come up with are:
1) subclass NSTableView. This has the advantage that I can use
the existing dataSource, and that I presume the drawing hooks
are already in place, but has the disadvantage that the
TableView has to be aware of the fact that it's embedded in an
NSClipView.
2) reimplement NSScrolledView to restrict the content view
slightly, and add a second content view with associated
1 row table below it. This seems like more work, but may
be the cleaner solution, although synchronizing the column
widths of the two tables will probably prove to be a bit
messy.
Does apple release the source to its cocoa controls? That would
be *exceedingly* useful (I got a lot from being able to poke
around in the Swing internals), but I doubt somehow that they
do.
Toby.
[and then, my solution]
Hi all,
I don't know if posting chunks of code like this is a breach of
etiquette. If it is, please say so.
Anyway, this is my solution to the problem of a summary row for
a scrolled TableView. It consists of two parts; A ScrollView
that adds a second contentView for the summary, and lays it out
with the
- (void) tile;
method, and a summary view which subclasses NSView and hijacks
parts of the table that it adds a summary for (specifically,
it uses the table's cells for drawing itself, and the table's
data source for fetching the summary information).
An example of its use would (given an appropriately changed
NSScrollView in IB) be:
- (void)
setUpSummaryForTable: (NSTableView *)master_table
{
MySummaryTableView *st =
[[[MySummaryTableView alloc]
initWithFrame: NSMakeRect(0,0,0,0)]
autorelease];
[st setMasterTable: master_table];
// the second superview of the table is the scroll view.
[((MyNSScrollView *)[[master_table superview] superview])
setSummaryDocumentView: st];
}
And then in the table data source for master_table:
- (id)
summaryObjectForColumn: (NSTableColumn *)column
{
...
}
If anyone has the time, I'd appreciate any comments, criticisms
or suggestions.
[
Obviously, I can't post attachments, so I'll stick the archive
at
http://www.csse.monash.edu.au/~tjs/MyScrollView.tgz
]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.