2
votes

I have a cell-based NSTableView that is unexpectedly resizing vertically as I continue to add more items to the table. I've implemented constraints, but they are obviously being broken.

Not sure if this is in any way related, but I don't seem to have this problem when the NSTableView is in a regular NSWindow - the issue only happens when the NSTableView is within an NSPopover (I understand that NSPopover does have a window, i.e. myPopover.contentViewController.view.window).

I've tried a number of things to stop autoresizing, but nothing is working.

This is what happens if I do not place a height constraint on the NSSegmentedControl below the NSTableView (it gets squished, oddly by what seems to be the NSScrollView resizing, and not the NSTableView):

enter image description here

This is what happens if I do place a height constraint on the NSSegmentedControl (the NSScrollView (height = 155) constraint is broken, and both the NSScrollView and the NSTableView resize):

enter image description here

Here are my constraints:

enter image description here

1
Did you add any constraints to the table view? To which view are the constraints of the segmented control attached?Willeke

1 Answers

0
votes

Well, I sort of have this fixed. By adding the following code, I can prevent the NSTableView from resizing as shown in the original question's example GIFs.

myTableView.superview.translatesAutoresizingMaskIntoConstraints = NO;

While the above code prevents the NSTableView from resizing unexpectedly, I still see an error logged about the NSScrollView height constraint being broken:

[Layout] Unable to simultaneously satisfy constraints:
...
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60000212f840 NSScrollView:0x600003d01680.height == 155   (active)>


I can get rid of this error by changing the NSScrollView's height constraint (shown in last screen shot in original question) from (height = 155) to (height >= 155). I still would prefer to force the height of both the NSScrollView and the NSTable view to remain at 155, however.

If no one else has an answer, I suppose I will use this fix until a better solution is identified.

For those wondering, I worked out this solution after reading this: https://www.hackingwithswift.com/example-code/uikit/how-to-stop-auto-layout-and-autoresizing-masks-conflicting-translatesautoresizingmaskintoconstraints