Layout still needs update after calling NSTableRowView layout

…衆ロ難τιáo~ 提交于 2019-12-10 05:58:55

问题


I have two NSTableView's in my app and the user can drag and drop items from table A to table B. When dragging an item to table B Xcode gives me the following layout warning message:

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.

This ever only happens when items are dragged to table B. I have otherwise no auto-layout warnings in IB and everything in the layout looks like being set up correctly. Does somebody know what the above message is trying to tell me? The tables are using standard Cocoa classes (not sub-classed).


回答1:


I fixed it (or rather worked around it) by having the drop operation type not being allowed except for NSTableViewDropOperation.Above. Before a user could drop them onto other rows, not just between rows. But I want them to be only be allowed to be dropped between rows so that's fine with me. Here's the code that fixed it:

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



回答2:


In my case the warning was slightly different.

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.

Different class NSView.

Anyway in my case, I could fix this by setting translatesAutoresizingMaskIntoConstraints == false of a NSScrollView.

For the record, autoresizingMask and autoresizesSubviews don't need to be touched at all.

The warning simply means that I have to set the property manually, otherwise it will produce wrong constraints. But figuring out the problematic object was very hard. I had to iterate all view nodes to check the property state.



来源:https://stackoverflow.com/questions/30621573/layout-still-needs-update-after-calling-nstablerowview-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!