gpt4 book ai didi

macos - NSTableView 在第一行上方有多余的空间

转载 作者:行者123 更新时间:2023-12-03 16:00:41 27 4
gpt4 key购买 nike

我有一个 NSTableView,其第一行从顶部向下推 10 pt。标题已关闭,没有分组行,单元格间距为 0,封闭 ScrollView 的内容插入为 0。

更新
这是 sample project这证明了这个问题。

这是 View 层次结构调试器的抓取:
enter image description here
这是第一行的 NSTableRowView 的垂直约束在 View 层次结构调试器中暂停时:
enter image description here
我尝试实现委托(delegate)的 tableView(_:didAdd:forRow:)并检查约束,首先使用 constraintsAffectingLayout(for:) :

[<NSLayoutConstraint:0x60000390bd40 'NSTableRowView_Encapsulated_Layout_Height' NSTableRowView:0x7fdb12e26eb0.height == 24 priority:500   (active)>]
然后打印所有行 View 的 constraints :
  - 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 )>
单元格的 minY约束设置为 0,但该行使用自动调整大小掩码。该表使用一个简单的 diffable 数据源:
NSTableViewDiffableDataSourceReference(tableView: table) { tableView, column, row, item in
guard let cell = tableView.makeView(withIdentifier: inlineCellIdentifier, owner: self) as? NSTableCellView else {
preconditionFailure("Failed to create results cell")
}
cell.textField?.textColor = self.themeAttributes.color
cell.textField?.font = self.themeAttributes.font
cell.textField?.stringValue = self.displayString(for: item)
return cell
}
唯一实现的委托(delegate)方法是 tableView(_:heightOfRow:) .该表与同级 TextView 的行对齐,因此它从那里获取行高:
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
guard let layoutManager = editor?.layoutManager else {
preconditionFailure("Missing layout manager in editor")
}
return height(of: row, in: layoutManager)
}
这似乎很明显,但我不明白为什么表会强制它的行像这样偏移。我在这个论坛上发现了很多问题,询问如何在表格顶部插入一个间隙,而不是如何删除一个。有什么建议吗?

最佳答案

正如一些评论中所说,这不是一个错误,它是 NSTableView 的一种新方式。在大苏尔工作(实际上有一个错误,但在其他地方,见下文)。免费的 Pascal 网站包含 nice overview of what's new .
NSTableView特性
macOS Big Sur 推出新的 NSTableView特性:

  • style
  • effectiveStyle
  • style文档:

    The default value for this property is NSTableView.Style.automatic in macOS 11. Apps that link to previous macOS versions default to NSTableView.Style.fullWidth.

    effectiveStyle文档:

    If the style property value is NSTableView.Style.automatic, then this property contains the resolved style.


    .automatic documentation :

    The system resolves the table view style in the following manner:

    • If the table view is in a sidebar split-view controller item, effectiveStyle resolves to NSTableView.Style.sourceList.
    • If the table’s scroll view has a border, effectiveStyle resolves to NSTableView.Style.fullWidth.
    • Otherwise effectiveStyle resolves to NSTableView.Style.inset. However, if the table needs extra space to fit its column cells, effectiveStyle resolves to NSTableView.Style.fullWidth.

    您的表格 View 的样式设置为 .automatic在 Main.storyboard 中。这意味着有效样式解析为 .inset -> 10pt 围绕内容(基于 .automatic 文档中的规则)。
    打开带有选定行的 View 调试器。你可以看到 .inset风格效果:
    enter image description here
    使用 .fullWidth删除 10pt 插图。
    您也可以测试 .automatic样式行为 - 尝试为 ScrollView 添加边框。解析为 .fullWidth .
    错误和解决方法
    您可能尝试在 Interface Builder 中将表格 View 样式设置为全宽。它不起作用。无论您选择什么值,它的行为都类似于 .automatic .
    将以下行添加到您的代码中以解决此问题:
    tableView?.style = .fullWidth
    现在按预期工作:
    enter image description here
    报告为 FB8258910。

    关于macos - NSTableView 在第一行上方有多余的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63175168/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com