在NSTableView中着色行 [英] Coloring a Row in an NSTableView

查看:179
本文介绍了在NSTableView中着色行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是当点击I按钮时,设置NSTableView中所选行的背景颜色。
我看过其他人使用 tableView:willDisplayCell:forTableColumn:row: setBackgroundColor:但我不认为这将工作在我想要的情况下,当一个按钮点击发生。

What I am looking to do is set the background color of the selected row in an NSTableView when a I button is clicked. I've seen other cases where people have used tableView:willDisplayCell:forTableColumn:row: and setBackgroundColor: but I don't think that will work in my situation where I want it to happen when a button is clicked.

我知道我可以找到所选行NSTableView的 selectedRow 方法并设置一个单元格的背景颜色与 setBackgroundColor:,但我不知道如何

I know that I can find the selected row with NSTableView's selectedRow method and set the Background color for a cell with setBackgroundColor:, but what I don't know how to do is get from a NSInteger for the selected row to an NSCell to set the background color of.

推荐答案

NSTableView 每个列仅使用一个 NSCell 实例。绘制内容时,将为每行更新单元格。这就是为什么没有方法来获取指定行的单元格 - 您必须修改 tableView:willDisplayCell:forTableColumn:row:中的单元格。

NSTableView uses only one instance of NSCell for each column. When drawing the contents, the cell is updated for each row. That’s why there’s no method to get a cell for a specified row—you have to modify the cell in tableView:willDisplayCell:forTableColumn:row:.

您可以使用 reloadDataForRowIndexes:columnIndexes:来告诉表视图只更新一行。

You can tell the table view to update only one row using reloadDataForRowIndexes:columnIndexes:.

这篇关于在NSTableView中着色行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆