Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created January 10, 2020 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/403f13a8b8c7002e04a4b4846502cb5c to your computer and use it in GitHub Desktop.
Save ycui1/403f13a8b8c7002e04a4b4846502cb5c to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let task = tasks[indexPath.row]
return UIContextMenuConfiguration(identifier: task.id as NSString, previewProvider: nil) { _ in
let shareAction = UIAction(
title: "Share",
image: UIImage(systemName: "square.and.arrow.up")) { _ in
// share the task
}
let copyAction = UIAction(
title: "Copy",
image: UIImage(systemName: "doc.on.doc")) { _ in
// copy the task content
}
let deleteAction = UIAction(
title: "Delete",
image: UIImage(systemName: "trash"),
attributes: .destructive) { _ in
// delete the task
}
return UIMenu(title: "", children: [shareAction, copyAction, deleteAction])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment