【问题标题】:Creating collapsible rows in NSTableview using swift使用 swift 在 NSTableview 中创建可折叠行
【发布时间】:2018-08-23 11:23:32
【问题描述】:

在 ios 中,我们为 UITableview 提供了可扩展的行,点击它会显示子行。

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

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

【问题讨论】:

  • 到目前为止你尝试过什么代码?
  • 你为什么不用 NSOutlineView?
  • @Carpsen90 我尝试使用 tableView 委托方法 insertRows(at: , withAnimation: ) 插入子行,但它正在创建一个重复的新行行号的值作为索引集传递。我需要在单击 nstableview 中的任何行时切换(隐藏/显示)子行。
  • @ElTomato 现在需要在 nstableview 中完成。所以没试过 NSoutlineView。
  • @sourav 插入行是一种即兴创作,它会弄乱模型并使代码不那么清晰。 Apple 处理扩展单元格的方法是更改​​单元格的高度以显示/隐藏单元格的其余部分。

标签: swift macos cocoa nstableview


【解决方案1】:

您可以在展开单元格的按钮上添加一个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 示例应用程序。

【讨论】:

  • 谢谢你..会试试这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-14
  • 2020-09-19
  • 1970-01-01
  • 2010-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多