Editing style for UICollectionView delete

The photo below shows a function to delete a section of a tableview.

 func tableView(_ tableView: UITableView, commit editingStyle:  UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == UITableViewCellEditingStyle.delete {
    let appd = UIApplication.shared.delegate as! AppDelegate
    let context = appd.persistentContainer.viewContext

    context.delete(itemName[indexPath.row])
    itemName.remove(at: indexPath.row)

    do {
        try context.save()
    } catch {
        print("d")
    }
    self.theTable.reloadData()
}

}
I want to know how do do the same thing with a UICollectionView

Hi @timswift, you can try using a pan gesture for deleting a cell within a UICollectionView. I’m not sure if you have already started something on your own or if you have more specific question but here is a tutorial using Swift 3 to do what you are asking. Pan Gesture with UICollectionView Cell .

Best,
Gina

This topic was automatically closed after 166 days. New replies are no longer allowed.