【发布时间】:2019-06-20 02:03:06
【问题描述】:
我想更改 NSTableView 中弹出按钮的索引。
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
let dataCell:NSPopUpButtonCell = tableColumn?.dataCell as! NSPopUpButtonCell
dataCell.addItems(withTitles: dataTypes)
return data.type //dataCell
}
func tableView(_ tableView: NSTableView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, row: Int) {
dataSourceArr[row].type = dataTypes[object as! Int]
tableView.reloadData()
}
我可以更新我的 dataSource 数组,但我不能在 tableView 中更新。
【问题讨论】:
-
它是基于视图还是基于单元格的表格视图?您应该在数据模型中保留弹出窗口的状态并使用 Cocoa Bindings。
-
@vadian 单元格表格视图 ...
-
强烈建议使用基于视图的表格视图。它们更容易维护
标签: swift xcode macos nstableview nspopupbuttoncell