swift - 使用 swift 在 NSTableview 中创建可折叠行

标签 swift macos cocoa nstableview

在 ios 中,我们为 UITableview 提供了可展开的行,单击后会显示子行。

我希望使用 swift 在 nstableview 的 mac osx 应用程序中实现类似的实现。

任何帮助将不胜感激。提前致谢。

最佳答案

您可以向展开单元格的按钮添加 IBAction,并调整单元格的高度自动布局约束:

//Set an IBOutlet to the cell's height constraint
@IBOutlet weak var heightConstraint: NSLayoutConstraint!

@IBAction func expandCellAction(_ sender: UIButton) {
    heightConstraint.constant = someValue
    yourView.layoutIfNeeded()
}

或者,如果您希望在选择单元格时展开该单元格,请使用此功能

func tableViewSelectionDidChange(_ notification: Notification) {
    heightConstraint.constant = someValue
    yourView.layoutIfNeeded()
}

看看this来自 Apple 的示例应用程序。

关于swift - 使用 swift 在 NSTableview 中创建可折叠行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51984678/

相关文章:

ios - 在扩展中创建便利 init 时为 `Ambiguous reference to member`

ios - fatal error : Index out of range: file Swift/ContiguousArrayBuffer. swift,第 444 行,有时可以工作

ios - 在使用 Alamofire + suggestedDownloadDestination 下载文件之前检查文件是否已经存在

ios - 在 swift 中关闭弹出窗口后更新标签文本

python - Django manage.py syncdb 抛出没有名为 MySQLdb 的模块

iphone - Cocoa - 不知从何而来的 NSError 描述

swift - NSStatusBar NSSMenuItem 中的 NSDatePicker 未接收输入

macos - 在空白 OS X Storyboard 中创建应用程序场景

objective-c - 读取别名文件

objective-c - 遍历二维数组,使用for-in语法