SMGreenfield SMGreenfield - 1 year ago 118
Objective-C Question

NSTableView won't layout / resize columns until NSWindow manually resized

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:

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

Column resizing mask is always:


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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download