简体   繁体   中英

Change data in selected cell at NSTableView

I have NSTableView with cell as custom views (NSCellView). How can I get reference to this cell and change data inside on selection of that cell?

From tableViewSelectionDidChange I can't get reference to this cell (empty notification), tableView willDisplayCell not working with cell as views, tableView.selectedCell() returning data only for default cells (not as views).

Call viewAtColumn(_:row:makeIfNecessary:) , passing the column index of the appropriate column, the index of the selected row, and true. You'll need to cast that to your cell view class.

By the way, don't use the NS prefix for your own classes ( NSCellView ). Use a prefix specific to your organization or project. NS is reserved for Cocoa.

Code example to access specified cell:

func tableView(tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
    let cell = tableView.viewAtColumn(0, row:row, makeIfNecessary:true)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM