NSTableViewCell setSelected? [英] NSTableViewCell setSelected?

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

问题描述

当我在tableView上选择该单元格时,该如何在 NSViewController NSTableViewCell 之间进行通信? 在iOS上,您可以使用setSelected,但在OSX中则完全不同. NSTableCellView类没有类似的功能.我可能缺少一些简单的东西.我该如何与该牢房交谈?我有一个自定义类单元,在tableView控制器上,我得到了:

How do I communicate between my NSViewController and the NSTableViewCell when I select that cell on my tableView? On iOS you could use setSelected but in OSX it is totally different. The NSTableCellView class doesn't have any function like that. I might be missing something simple. How do I talk with that cell? I have a custom class cell and on my tableView controller, I got:

func tableView(tableView: NSTableView, shouldSelectRow row: Int) -> Bool {

    let previousSelected = NSIndexSet(index: selectedRow)
    selectedRow = row
    let indset = NSIndexSet(index: row)

    // animate row expansion
    self.tableView.noteHeightOfRowsWithIndexesChanged(indset)

    // animate back the previously selected
    self.tableView.noteHeightOfRowsWithIndexesChanged(previousSelected)
    return true
}

我也有Row的身高...

I also have the height of Row...

func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
    if row == selectedRow{
        return 90
    }else{
        return 40
    }
}

我想做的是让我的单元格知道它已被选中,因此它在被选中时可以显示不同的内容.有人吗?

What I'm trying to do is to let my cell know it got selected, so it can display different things when selected. Anyone ?

推荐答案

选择不适用于单元格,而是适用于行. NSTableRowView具有selected属性.通常负责使用drawSelectionInRect()方法绘制表行的选定外观.

Selection doesn't operate on cells, it operates on rows. NSTableRowView has a selected property. It's generally responsible for drawing the selected appearance of table rows with its drawSelectionInRect() method.

您的单元格根据其是否被选中而准确地改变其行为或外观?您确定不应该按行执行吗?也许您应该使用NSTableRowView的自定义子类.

How exactly does your cell change its behavior or appearance based on whether it's selected? Are you sure that shouldn't be done by the row, instead? Perhaps you should be using a custom subclass of NSTableRowView.

如果必须的话,可以从单元格视图中找到行视图.一种方法是仅假定单元格的超级视图是行视图,而不是nil时应为行视图.另一种方法是使用rowForView(self)询问表格视图该单元格的哪一行,然后使用rowViewAtRow(_:makeIfNecessary:)询问表格视图的行视图.

If you must, you can find the row view from the cell view. One way is to just assume the cell's superview is the row view, which it should be when it's not nil. Another approach is to ask the table view which row the cell is for using rowForView(self) and then ask the table view for the row view using rowViewAtRow(_:makeIfNecessary:).

这篇关于NSTableViewCell setSelected?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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