NSTableViewRowAction - 点击后滑回

问题描述 投票:2回答:1

我添加了一个滑动功能,以我的表视图使用tableView(_:rowActionsForRow:edge:) -> [NSTableViewRowAction],但我发现,当我点击按钮龙头,它工作正常,但它只是不滑回。

这是我行操作的代码:

extension ViewController: NSTableViewDelegate {
    func tableView(_ tableView: NSTableView, rowActionsForRow row: Int, edge: NSTableView.RowActionEdge) -> [NSTableViewRowAction] {
        // some other codes
        switch edge {
        case .trailing:
            // some other codes
        case .leading:
            let revealInFinderAction = NSTableViewRowAction(style: .regular, title: "Reveal in Finder") { (action, row) in
                self.revealInFinder(row: row)
            }
            revealInFinderAction.backgroundColor = .systemOrange
            return [revealInFinderAction]
        }
    }
}

例如,我的一个按钮,那么“在Finder中显示”作业(revealInFinderAction),点击按钮后,它揭示了在Finder中的文件,但它并没有向后滑动。

我发现苹果的Mail应用程序可以完美解决这个问题,点击标记为已读/未读按钮滑动的一个细胞后后,又做其工作,并自动滑回。我只是想找到一种方法,让同样的事情发生。

我已经做了关于如何实现这一目标的研究,但我找不到它的解决方案,是否有任何人能帮助我吗?我在Mac OS 10.14使用Xcode的10斯威夫特4。

cocoa swift4 nstableview xcode10 macos-mojave
1个回答
2
投票

尝试设置tableView.rowActionsVisible = false,就像这样:

case .leading:
        let revealInFinderAction = NSTableViewRowAction(style: .regular, title: "Reveal in Finder") { (action, row) in
            self.revealInFinder(row: row)
            tableView.rowActionsVisible = false
        }
        revealInFinderAction.backgroundColor = .systemOrange
        return [revealInFinderAction]
© www.soinside.com 2019 - 2024. All rights reserved.