NSTableView 只在单元格被选中时显示按钮 [英] NSTableView only display button when cell is selected

查看:23
本文介绍了NSTableView 只在单元格被选中时显示按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于视图模式的 NSTableview,在其中我有自定义的 NSTableViewCells.每个单元格都有一个按钮,但我只希望在选择单元格时显示该按钮.所以当单元格被取消选择时,我想隐藏按钮.我试图遍历每一行但没有成功,我不确定如何解决这个问题.

I have an NSTableview in view based mode, in it I have custom NSTableViewCells. Each cell has a button, but I only want the button to be displayed if the cell is selected. So when the cell becomes deselected I want to hide the button. I have tried to iterate through each row unsuccessfully and am unsure as to how to go about this.

这是为了显示按钮

-(void)tableViewSelectionDidChange:(NSNotification *)notification
{
    ...

    //Hide / show dropdown menus
    NSInteger selected = [_tableView selectedRow];
    CustomCell *cell = [_tableView viewAtColumn:0 row:selected makeIfNecessary:NO];
    [cell setIsMenuHidden:NO];

}

推荐答案

在您的自定义单元格视图中,您可以覆盖 -viewWillDraw.调用 super,然后根据您想要的状态进行任何调整.

In your custom cell view, you can override -viewWillDraw. Call through to super and then make whatever adjustments based on the state that you want.

您可以使用表格视图的 -rowForView:-isRowSelected: 方法来确定是隐藏还是显示按钮.或者,单元格视图的超级视图将是行视图,并且 NSTableRowView 有一个 selected 属性(-isSelected getter).

You can use the table view's -rowForView: and -isRowSelected: methods to determine whether to hide or show the button. Alternatively, the cell view's superview will be the row view and NSTableRowView has a selected property (-isSelected getter).

这篇关于NSTableView 只在单元格被选中时显示按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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