Invalid restrictions with NSTableView when calling reloadData

I have a view-based NSTableView with a graphical representation of an NSTableCellView table graphically through an interface constructor in the latest version of Xcode 10.8.2.

When I call -reloadData on an NSTableView, it crashes:

Unable to simultaneously satisfy constraints: ( "<NSAutoresizingMaskLayoutConstraint:0x105cb8bf0 h=--& v=--& V:[NSTableRowView:0x105ca7020(0)]>", "<NSAutoresizingMaskLayoutConstraint:0x10596aa30 h=--& v=-&- V:[GroupTableRowView]-(2)-| (Names: GroupTableRowView:0x100185860, '|':NSTableRowView:0x105ca7020 )>", "<NSAutoresizingMaskLayoutConstraint:0x1058d9770 h=--& v=-&- V:|-(1)-[GroupTableRowView] (Names: GroupTableRowView:0x100185860, '|':NSTableRowView:0x105ca7020 )>" ) Will attempt to recover by breaking constraint <NSAutoresizingMaskLayoutConstraint:0x10596aa30 h=--& v=-&- V:[GroupTableRowView]-(2)-| (Names: GroupTableRowView:0x100185860, '|':NSTableRowView:0x105ca7020 )> 

I cannot turn off the translation of the auto-change mask in any of the views, since their limitations are controlled by NSTableView. Clearly, the restrictions are inconsistent because the NSTableRowView cannot have a height of 0, but it still satisfies the two other restrictions in the GroupTableRowView that indicate mandatory padding between the superview (row view?). I am not sure how to solve this, any ideas would be appreciated. Thanks!

Update : I found a workaround. The problem is that for some reason the NSTableRowView is sending the frame size {0, 0} when calling -reloadData in the table view. I tried -setFrameSize: in a subclass of NSTableRowView and passed the message only to the responder chain when the size is not {0,0} .

 - (void)setFrameSize:(NSSize)newSize { if (!NSEqualSizes(newSize, NSZeroSize)) [super setFrameSize:newSize]; } 

To use a subclass, implement the NSTableViewDelegate method - tableView: rowViewForRow: to return an instance of a custom subclass.

 - (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row { id rowView = [[GroupTableRowView alloc] init]; // configure any custom properties return rowView; } 

If the table view is completely constructed in IB, you can simply drag and drop the new NSView into the table view and set its own class to a subclass of NSTableRowView and change its UI element identifier to NSTableViewRowViewKey

+6
source share
2 answers

I had the same problem and it always got me nuts ..

I solved this using your code, but subclassing NSTableRowView instead of NSTableCellView . To automatically allow the table to use your own row view, add a custom NSView to your table. Set your class to your own row view and, importantly, its identifier is NSTableViewRowViewKey .

With this special identifier, the table automatically uses it as a row representation.

+1
source

I had a similar problem, but with column width, not row height. Unused autodetection restrictions appeared on NSTableView -based NSTableView cells immediately after calling reloadData . In my case, this was caused by setting the minimum width to NSTableColumn , which was too small to contain the minimum width for the restrictions in the cell. Therefore, for those who have a similar problem, I would first check this out.

The “interesting” part was that it was a problem only for reloadData , and not for the normal layout, because there were restrictions on the width of the NSTableView , which prevented it from ever ever trying to create a cell, But when reloadData is reloadData , it will apparently it first creates a new cell with the frame size set to the minimum column width, before changing the column size to an earlier fit (if you have a table configured for this). Therefore, despite the fact that everything seemed to work fine, it still spits out an error about unsatisfactory restrictions immediately after calling reloadData , since the initial width of the cell view is too small to fill, etc.

The moral of the story is to always verify that the minimum width of the NSTableColumn is large enough for restrictions in the cell, even if you don't think the column will ever be so small. IB makes it easy to tinker with restrictions, and it's easy to forget to double-check the column width settings after changing anything in the cells.

+1
source

All Articles