调用 NSTableRowView 布局后布局仍需要更新

Layout still needs update after calling NSTableRowView layout

我的应用程序中有两个 NSTableView,用户可以将项目从 table A 拖放到 table B。将项目拖动到 table B 时 Xcode 给我以下布局警告消息:

Layout still needs update after calling -[NSTableRowView layout]. NSTableRowView or one of its superclasses may have overridden -layout without calling super. Or, something may have dirtied layout in the middle of updating it. Both are programming errors in Cocoa Autolayout. The former is pretty likely to arise if some pre-Cocoa Autolayout class had a method called layout, but it should be fixed.

只有当项目被拖到 table B 时才会发生这种情况。否则我在 IB 中没有自动布局警告,布局中的所有内容看起来都设置正确。有人知道上面的消息想告诉我什么吗? table 使用标准 Cocoa 类(未分类)。

我通过不允许除 NSTableViewDropOperation.Above 之外的 drop 操作类型来修复它(或者更确切地说是解决它)。在用户可以将它们 放到 其他行之前,而不仅仅是行之间。但我希望只允许将它们放在行之间,所以这对我来说很好。这是修复它的代码:

func tableView(aTableView:NSTableView, validateDrop info:NSDraggingInfo, proposedRow row:Int, proposedDropOperation operation:NSTableViewDropOperation) -> NSDragOperation
{
    if (operation == .Above) { return .Move; }
    return .None;
}

在我的例子中,警告略有不同。

Layout still needs update after calling -[NSView layout]. NSView or one of its superclasses may have overridden -layout without calling super. Or, something may have dirtied layout in the middle of updating it. Both are programming errors in Cocoa Autolayout. The former is pretty likely to arise if some pre-Cocoa Autolayout class had a method called layout, but it should be fixed.

不同 class NSView.

无论如何,我可以通过设置 NSScrollViewtranslatesAutoresizingMaskIntoConstraints == false 来解决这个问题。

郑重声明,autoresizingMaskautoresizesSubviews 根本不需要修改。

警告只是意味着我必须手动设置 属性,否则会产生错误的约束。但是找出有问题的对象非常困难。我不得不迭代所有视图节点以检查 属性 状态。