Re: Sizing NSTableView to data
Re: Sizing NSTableView to data
- Subject: Re: Sizing NSTableView to data
- From: Kyle Sluder <email@hidden>
- Date: Tue, 17 Jul 2012 22:13:41 -0700
On Thu, Jun 28, 2012, at 04:42 PM, Maury Markowitz wrote:
> I am working on the ODBCkit's Query Tool to make it work across a wide
> variety of data sources - so far all the major commercial DB's, Firebird,
> MySQL and even SQLite! Got an ODBC target and test DB you'd like to test?
> Throw it my way!
>
> One problem that's come up in a couple of different places is that many
> SQL data types are fixed-width. I ask the recordset for the width, but it
> lies - it says 255 chars, but in fact there's only maybe 25 characters
> actually in the field. It is also surprisingly common to find numbers
> held in huge fixed-char fields. When I space out my TableView based on
> what the DB tells me, I end up with lots of whitespace.
>
> I notice that *after* the DataSource is done setting up and the data is
> in the display, double-clicking the "divider line" in the header gives me
> perfect results. Is there a way to simulate that double-click in code?
> Ideally I'd like to find out what the width would be if I did the action,
> then adjust it for max/min sizes in the code.
According to the AppKit release notes [1], NSTableView sizes a column to
fit by taking the maximum of the sizes of the preparedCellAtRow:column:
for some number of rows. (I believe Corbin has said it takes a random
subset when the number of rows in the data source is large). This is
presumably why they recommend you implement
-tableView:sizeToFitWidthOfColumn: yourself rather than have NSTableView
do it.
I'd say you should file an enhancement request asking for the ability to
ask NSTableView to size a particular column to fit, just as if the user
had double-clicked the divider in the header, as it only seems to have
methods that distribute remaining size uniformly or only to the last
column.
In the meantime, implement -tableView:sizeToFitWidthOfColumn: to return
the right value for each column, and then just call -sizeToFit on the
table view.
[1]
https://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKitOlderNotes.html
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden