I have a view-based NSTableView with the table view's NSTableCellView's setup graphically through interface builder in the latest version of Xcode on 10.8.2.
When I call -reloadData on the NSTableView, it crashes with:
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 can't turn off auto-resizing mask translation on any of the views involved as their constraints are managed by the NSTableView. It's clear that the constraints are conflicting because the NSTableRowView can't possibly have a 0 height while still satisfying the other two constraints on the GroupTableRowView that specify mandatory padding between the superview (the row view?). I'm not sure how to resolve this, any insights would be greatly appreciated. Thanks!
Update:
I found a workaround. The issue is that for some reason the NSTableRowView was being sent a frame size of {0, 0}
when calling -reloadData on the table view. I overrode -setFrameSize:
in the NSTableRowView subclass and only pass the message up the responder chain when the size is not {0,0}
.
- (void)setFrameSize:(NSSize)newSize
{
if (!NSEqualSizes(newSize, NSZeroSize))
[super setFrameSize:newSize];
}
To use the subclass, implement NSTableViewDelegate's -tableView:rowViewForRow: method to return an instance of the 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 designed entirely in IB, you can simply drag a new NSView into your table view and set it's custom class to your NSTableRowView subclass and change it's User Interface Item Identifier to NSTableViewRowViewKey
{0,0}
but I can't reproduce this in a demo app to submit with a bug report to Apple. – Andrew