Created
August 11, 2018 15:13
-
-
Save vulgur/a48c454676f3d013c1ce32474825122b to your computer and use it in GitHub Desktop.
[Leading and Trailing Action on Cell] #swipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
guard let product = dataStore?.products[indexPath.row] else { | |
return nil | |
} | |
let addAction = UIContextualAction(style: .normal, title: "Add") { [weak self](action, view, completionHandler) in | |
guard let `self` = self else { | |
completionHandler(false) | |
return | |
} | |
self.listController?.addItem(named: product.name) | |
completionHandler(true) | |
} | |
addAction.backgroundColor = UIColor.ggGreen | |
let configuration = UISwipeActionsConfiguration(actions: [addAction]) | |
return configuration | |
} | |
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
guard let product = dataStore?.products[indexPath.row] else { | |
return nil | |
} | |
let copyAction = UIContextualAction(style: .normal, title: "Copy") { (action, view, completionHandler) in | |
let data = NSKeyedArchiver.archivedData(withRootObject: product) | |
UIPasteboard.general.setData(data, forPasteboardType: Product.productTypeId) | |
completionHandler(true) | |
} | |
copyAction.backgroundColor = UIColor.ggDarkGreen | |
let configuration = UISwipeActionsConfiguration(actions: [copyAction]) | |
return configuration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment