sizeToFit simply sets the width of a column to the width of the header cell - and I suspect that you want to set the width of each column to suit the widest cell of data in that column.

Here is the heuristic to achieve that:

( Assuming that you have not changed the font for any of the cells ... )


[A]
get a table column - get the dataCell for the column - send it the font message.
Assume we assign it to a variable  tableFont

[B]
Create an attributes dictionary with tableFont  like this ...

NSMutableDictionary *attributes = [NSMutableDictionary  dictionary];
[attributes  setObject:tableFont  forKey:NSFontAttributeName];


[C]
Then, by using the table data source, you use this attributes dictionary to check
the written size of all the data - column by column.
i.e. take each column and iterating over the data for each row in that column,
hence deducing the max width of the column....

        NSSize  writtenSize = [dataString  sizeWithAttributes:attributes];

[D]
Having collected the widths of all the columns, iterate over the columns
and set their widths - then you may need to send the table view a tile message
to sort itself out.

Don't forget to set your max width on your columns to something sensible.


( P G J H )
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to