在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()
}


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

09-15 16:42