在 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/