问题描述
如何为基于 NSTableView
的视图绘制自定义选择样式?我尝试在 NSTableCellView
子类中设置 BOOL
var,并将其设置为 YES
如果它被点击,然后我可以成功地绘制我的自定义选择。但是当单击另一个视图时,如何将 BOOL
var更改为 NO
?感谢任何帮助。
How do I go about drawing my own custom selection style for a view based NSTableView
? I tried putting a BOOL
var in my NSTableCellView
subclass and set that to YES
if it is clicked and then I can successfully draw my custom selection. But how do I change that BOOL
var to NO
when another view is clicked? Thanks for any help.
编辑:阅读通过NSTableView文档后,它看起来像我需要子类NSTableRowView覆盖选择绘图,但我该怎么办NSTableRowView子类?如何获得表格使用它?
After reading through the NSTableView docs, it looks like I need to subclass NSTableRowView to override the selection drawing, but what do I do with my NSTableRowView subclass? How do I get the table to use it?
推荐答案
好吧,我想出来了。你只需要子类 NSTableRowView
。它具有绘制选定和取消选择行的背景的方法。要使表视图使用您的子类,只需实现表视图委托方法 tableView:rowViewForRow:
并返回您的子类的实例。
Alright, I figured it out. You just have to subclass NSTableRowView
. It has methods for drawing the background for selected and deselected rows. To get the table view to use your subclass just implement the table view delegate method tableView:rowViewForRow:
and return an instance of your subclass.
这篇关于在基于视图的NSTableView中处理自定义选择样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!