NSTableViewRowAction - 点击后向后滑动

NSTableViewRowAction - Slide back after clicking

我使用 tableView(_:rowActionsForRow:edge:) -> [NSTableViewRowAction] 向我的 table 视图添加了一个滑动功能,但我发现当我单击前导按钮时,它工作正常,但它不会向后滑动。

这是我的行操作的代码:

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]
        }
    }
}

例如, 我的一个按钮执行 "Reveal in Finder" 作业 (revealInFinderAction),单击该按钮后,它会在 Finder 中显示该文件, 但它没有向后滑动。

我发现 Apple 的邮件应用程序可以完美地处理这个问题,在滑动其中一个单元格后单击标记为 read/unread 按钮后,它完成了它的工作并自动向后滑动。我只是想找到一种方法让同样的事情发生。

我已经研究过如何实现这一点,但找不到解决方案,请问有人可以帮助我吗?我在 macOS 10.14 上使用 Xcode 10 和 Swift 4。

尝试设置 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]