smr*_*smr 9 macos nstableview appkit macos-big-sur
我有一个 NSTableView,它的第一行从顶部向下推 10 pt。标题被关闭,没有组行,单元格间距为 0,封闭滚动视图的内容插入为 0。
更新
这是一个演示该问题的示例项目。
这是视图层次结构调试器的抓图:
这是NSTableRowView在视图层次结构调试器中暂停时第一行的垂直约束:
我尝试实现委托的tableView(_:didAdd:forRow:)并检查约束,首先使用约束AffectingLayout (for:):
[<NSLayoutConstraint:0x60000390bd40 'NSTableRowView_Encapsulated_Layout_Height' NSTableRowView:0x7fdb12e26eb0.height == 24 priority:500 (active)>]
Run Code Online (Sandbox Code Playgroud)
然后打印所有行视图的约束:
- 0 : <NSLayoutConstraint:0x60000390bcf0 'NSTableRowView_Encapsulated_Layout_Width' NSTableRowView:0x7fdb12e26eb0.width == 329 priority:500 (active)>
- 1 : <NSLayoutConstraint:0x60000390bd40 'NSTableRowView_Encapsulated_Layout_Height' NSTableRowView:0x7fdb12e26eb0.height == 24 priority:500 (active)>
- 2 : <NSAutoresizingMaskLayoutConstraint:0x60000390bbb0 h=--& v=-&- InlineCell.minX == 16 (active, names: InlineCell:0x7fdb12e283a0, '|':NSTableRowView:0x7fdb12e26eb0 )>
- 3 : <NSAutoresizingMaskLayoutConstraint:0x60000390bc00 h=--& v=-&- InlineCell.width == 297 (active, names: InlineCell:0x7fdb12e283a0 )>
- 4 : <NSAutoresizingMaskLayoutConstraint:0x60000390bc50 h=--& v=-&- InlineCell.minY == 0 (active, names: InlineCell:0x7fdb12e283a0, '|':NSTableRowView:0x7fdb12e26eb0 )>
- 5 : <NSAutoresizingMaskLayoutConstraint:0x60000390bca0 h=--& v=-&- V:[InlineCell]-(0)-| (active, names: InlineCell:0x7fdb12e283a0, '|':NSTableRowView:0x7fdb12e26eb0 )>
Run Code Online (Sandbox Code Playgroud)
单元格的minY约束设置为 0,但该行使用自动调整大小掩码。该表使用一个简单的 diffable 数据源:
[<NSLayoutConstraint:0x60000390bd40 'NSTableRowView_Encapsulated_Layout_Height' NSTableRowView:0x7fdb12e26eb0.height == 24 priority:500 (active)>]
Run Code Online (Sandbox Code Playgroud)
唯一实现的委托方法是tableView(_:heightOfRow:)。表格将自己与同级文本视图的行对齐,因此它从那里获取行高:
- 0 : <NSLayoutConstraint:0x60000390bcf0 'NSTableRowView_Encapsulated_Layout_Width' NSTableRowView:0x7fdb12e26eb0.width == 329 priority:500 (active)>
- 1 : <NSLayoutConstraint:0x60000390bd40 'NSTableRowView_Encapsulated_Layout_Height' NSTableRowView:0x7fdb12e26eb0.height == 24 priority:500 (active)>
- 2 : <NSAutoresizingMaskLayoutConstraint:0x60000390bbb0 h=--& v=-&- InlineCell.minX == 16 (active, names: InlineCell:0x7fdb12e283a0, '|':NSTableRowView:0x7fdb12e26eb0 )>
- 3 : <NSAutoresizingMaskLayoutConstraint:0x60000390bc00 h=--& v=-&- InlineCell.width == 297 (active, names: InlineCell:0x7fdb12e283a0 )>
- 4 : <NSAutoresizingMaskLayoutConstraint:0x60000390bc50 h=--& v=-&- InlineCell.minY == 0 (active, names: InlineCell:0x7fdb12e283a0, '|':NSTableRowView:0x7fdb12e26eb0 )>
- 5 : <NSAutoresizingMaskLayoutConstraint:0x60000390bca0 h=--& v=-&- V:[InlineCell]-(0)-| (active, names: InlineCell:0x7fdb12e283a0, '|':NSTableRowView:0x7fdb12e26eb0 )>
Run Code Online (Sandbox Code Playgroud)
这似乎很明显,但我不明白为什么表会强制其行像这样偏移。我在这个论坛上发现了很多问题,询问如何在桌子顶部插入一个间隙,而不是如何删除一个。有什么建议吗?
zrz*_*zka 18
正如某些评论中所述,这NSTableView不是错误,而是 Big Sur 中的一种新工作方式(实际上存在错误,但在其他地方,请参见下文)。Free Pascal 站点包含对新内容的很好的概述。
NSTableView房源macOS Big Sur 引入了新NSTableView属性:
style 文档:
此属性的默认值
NSTableView.Style.automatic在 macOS 11 中。链接到先前 macOS 版本的应用程序默认为NSTableView.Style.fullWidth。
effectiveStyle 文档:
如果
style属性值为NSTableView.Style.automatic,则此属性包含已解析的样式。
系统通过以下方式解析表格视图样式:
- 如果表视图在侧边栏拆分视图控制器项中,则
effectiveStyle解析为NSTableView.Style.sourceList.- 如果表格的滚动视图有边框,则
effectiveStyle解析为NSTableView.Style.fullWidth。- 否则
effectiveStyle解析为NSTableView.Style.inset。但是,如果表格需要额外的空间来容纳其列单元格,则effectiveStyle解析为NSTableView.Style.fullWidth。
您的表视图.automatic在 Main.storyboard 中设置了样式。这意味着有效样式解析为.inset-> 10pt 围绕内容(基于.automatic文档中的规则)。
打开带有选定行的视图调试器。可以看到.inset样式效果:
使用.fullWidth删除10PT插图。
您还可以测试.automatic样式行为 - 尝试向滚动视图添加边框。解析为.fullWidth.
您可能尝试在界面生成器中将表格视图样式设置为全宽。它不起作用。无论您选择什么值,它的行为都像.automatic.
将以下行添加到您的代码中以解决此问题:
tableView?.style = .fullWidth
Run Code Online (Sandbox Code Playgroud)
现在按预期工作:
报告为 FB8258910。
| 归档时间: |
|
| 查看次数: |
1296 次 |
| 最近记录: |