How to update row heights of NSTableView with usesAutomaticRowHeights = true after column resize?

房东的猫 提交于 2019-12-01 01:30:19

Something that worked for me was to include the tableViewColumnDidResize notification method in the NSTableviewDelegate. There you can call the noteHeightOfRows method of the table view. Here is an implementation:

   //Recalculate when the screen moves
   func tableViewColumnDidResize(_ notification: Notification) {
     let allIndex = IndexSet(integersIn:0..<self.YOURTABLE.numberOfRows)
    YOURTABLE.noteHeightOfRows(withIndexesChanged: allIndex)
}

Here are the links to the documentation: tableViewColumnDidResize and noteHeightOfRows

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.

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