Skip to content

Instantly share code, notes, and snippets.

@yusufozgul
Created February 28, 2020 12:40
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 yusufozgul/b8aee1827ad3eba84dcedd3d7ea5ea79 to your computer and use it in GitHub Desktop.
Save yusufozgul/b8aee1827ad3eba84dcedd3d7ea5ea79 to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let config = UIContextMenuConfiguration(identifier: "\(indexPath.row)" as NSCopying, previewProvider: {
return DetailViewController(selectedText: self.array[indexPath.row])
}) { action in
let viewMenu = UIAction(title: "Go Detail VC", image: UIImage(systemName: "eye.fill"), identifier: UIAction.Identifier(rawValue: "view")) {_ in
self.present(DetailViewController(selectedText: "\(indexPath.row)"), animated: true)
}
let deleteMenu = UIAction(title: "Delete", image: UIImage(systemName: "trash.fill"), identifier: nil) { (action) in
self.array.remove(at: indexPath.row)
tableView.reloadData()
}
let addMenu = UIAction(title: "Add", image: UIImage(systemName: "plus.rectangle.fill"), identifier: nil) { (action) in
self.array.append(self.array.randomElement() ?? "")
tableView.reloadData()
}
let secondMenu = UIMenu(title: "Edit", children: [deleteMenu, addMenu])
return UIMenu(title: "", image: nil, identifier: nil, children: [viewMenu, secondMenu])
}
return config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment