I've been testing this on the simulator. Perhaps that's why it doesn't work solidly. I have a custom UICollectionViewListCell. Some times, quite often, the cell remains after I swipe to delete. However, the cell is inoperative. Sometimes, the cell selects and slides over, but there appears to be two cells in one spot and the cell does not delete and is still operational. Here's my current code with some of it commented out because I am easter-egging a solution.
I'm sure I am doing something wrong. if anybody has a better solution or the correct solution, I'd like to know about it.
Thanks.
Code Block config.trailingSwipeActionsConfigurationProvider = { [weak self] indexPath in guard let self = self else { return nil } if indexPath.row > 0 { let cell = self.dataSource.collectionView(self.collectionView, cellForItemAt: indexPath) as! SavedVacationCell let vacation = cell.vacation! print("Going to delete it.") let actionHandler: UIContextualAction.Handler = { action, view, completion in action.image = UIImage(systemName: "trash") // var snap = self.dataSource.snapshot() // snap.deleteItems([vacation]) // self.dataSource.apply(snap, animatingDifferences: true) if vacation.uuid!.count == 36 { self.vacations?.removeAll(where: {$0.uuid == vacation.uuid}) var snap = self.dataSource.snapshot() snap.deleteAllItems() self.setSnapshot() // self.loadSavedData() // self.saveDataToAppleWatch() } self.deleteVacationAndReload(vacation) completion(true) } let action = UIContextualAction(style: .destructive, title: "Delete", handler: actionHandler) action.image = UIImage(systemName: "trash.fill") action.backgroundColor = .systemRed return UISwipeActionsConfiguration(actions: [action]) } return nil }
I'm sure I am doing something wrong. if anybody has a better solution or the correct solution, I'd like to know about it.
Thanks.