我想在NSTableView中更改popUp按钮的索引。
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中更新。
发布于 2019-01-28 16:01:02
您可以使用NSTableViewDelegate的willDisplayCell方法来实现此目的。
extension ViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, willDisplayCell cell: Any, for tableColumn: NSTableColumn?, row: Int) {
guard let dataCell = cell as? NSPopUpButtonCell else {return}
dataCell.selectItem(at: row) // or dataCell.selectItem(withTitle: //title)
}
}https://stackoverflow.com/questions/54378780
复制相似问题