0
votes

I've an NSTableView with several NSTableColumn objects that appear to have all the correct auto-resizing flags set. However, every time I rebuild the table's contents, the columns all return to a narrow size -- unless I click and manually resize the window.

The NSTableView is inside:

NSWindow NSView NSScrollView NSTableView (other NSTableView objects: NSTableColumn, NSTextFieldCell, NSScroller (x 2)

Column resizing mask is always:

NSTableColumnAutoresizingMask
NSTableColumnUserResizingMask

The table is created always set with:

[theNSTableView setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle];

After reloading the table with data,

[theNSTableView reloadData];
[theNSTableView tile];

...and even:

[theNSTableView setNeedsDisplay:YES];

All views are set to "autoresizesSubviews".

Neither the NSView nor the NSScrollView have any referencing outlets -- could that be the problem?

1
What do you call to reload the table's contents? When does this reload happen? Do you ever change the columns at run time?Wil Shipley
@WilShipley -- At various times that there are substantial changes, I go through and delete the columns, then re-add them. The call to reloadData does properly populate the table. Since posting, I have found out a little about this problem from Apple DTS, which I'll detail below.SMGreenfield

1 Answers

1
votes

After discussing this issue at length with Apple Developer Technical Support, they believe there may be an issue with Carbon-Cocoa integration.

However, they also point out that I really should not set NSTableViewUniformColumnAutoresizingStyle and I should be calculating the widths of all my columns in my own code, and then either telling the column to remember its width, or storing the width and making sure to set the same width on each column AFTER I programmatically create the column.

While I can accept this, I had been at least hoping I could programmatically invoke the same method that is called when a user double-clicks on a column divider and the column resizes itself to fit all of its cell text contents. However, DTS tells me those functions are not available.

I have come across other solutions to this issue here on SO and I will see if they can be adapted to create an optimal solution.