I added a slide feature to my table view using tableView(_:rowActionsForRow:edge:) -> [NSTableViewRowAction]
, but I found that when I click the leading button, it works fine, but it just doesn't slide back.
This is the code for my row action:
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]
}
}
}
For example, one of my buttons does the "Reveal in Finder" job (revealInFinderAction
), after clicking the button, it revealed the file in the Finder, but it didn't slide back.
I found that Apple's Mail app can perfectly handle this, after clicking the Mark as read/unread button after sliding one of the cells, it did its job and automatically slide back. I just want to find a way to make the same thing happen.
I've done research on how to achieve this, but I cannot find a solution for it, is there anyone can help me please? I'm using Xcode 10 with Swift 4 on macOS 10.14.
Try setting tableView.rowActionsVisible = false
, like this:
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]