问题描述
自macOS 10.13起,由于新属性usesAutomaticRowHeights
和自动布局,我们可以使用具有自动行高的NSTableView.效果很好.
Since macOS 10.13 we can use NSTableView with automatic row heights, thanks to the new property usesAutomaticRowHeights
and of course auto layout. This works quite nicely.
但是当用户调整列的大小时,计算出的高度不再正确,并且在表格视图单元格中出现了间隙.
But when the user resizes a column, the calculated heights are no longer correct, and gaps appear in the tableview cells.
在这种情况下,是否有行之有效的方法来在列调整大小后更新行高?
Is there a proven way to update the row heights after column resize in this scenario?
我已经尝试过updateConstraintsForSubtreeIfNeeded()
,updateConstraints()
,setNeedsDisplay()
,reloadData()
等方法,但是没有任何效果.
I already tried methods like updateConstraintsForSubtreeIfNeeded()
, updateConstraints()
, setNeedsDisplay()
, reloadData()
and so on, but nothing works.
推荐答案
如果在设计中使用NSTextField,请确保将每个具有动态高度的NSTextField的Desired Width
设置设置为Automatic
.此设置位于大小"检查器中.
If you use NSTextField's in your design, make sure the Desired Width
setting of each NSTextField with dynamic height, is set to Automatic
. This setting is located in the Size Inspector.
对此进行更改会导致自动重新计算表格视图行高.
Changing this resulted in automatic recalculation of the tableview row heights.
这篇关于列调整大小后,如何使用usesAutomaticRowHeights = true更新NSTableView的行高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!