如何在列调整大小后使用 usesAutomaticRowHeights = true 更新 NSTableView 的行高? [英] How to update row heights of NSTableView with usesAutomaticRowHeights = true after column resize?

查看:10
本文介绍了如何在列调整大小后使用 usesAutomaticRowHeights = true 更新 NSTableView 的行高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 macOS 10.13 开始,我们可以使用具有自动行高的 NSTableView,这要归功于新属性 usesAutomaticRowHeights,当然还有自动布局.这很好用.

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 设置设置为 自动.此设置位于尺寸检查器中.

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.

更改此设置会导致自动重新计算 tableview 行高.

Changing this resulted in automatic recalculation of the tableview row heights.

这篇关于如何在列调整大小后使用 usesAutomaticRowHeights = true 更新 NSTableView 的行高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆