Created
July 3, 2020 12:41
-
-
Save stevencurtis/c36e00b482c157711084899e97b44bf0 to your computer and use it in GitHub Desktop.
cell registration
This file contains 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
let registrationUICollectionViewListCell = UICollectionView.CellRegistration<UICollectionViewListCell, String> { (cell, indexPath, item) in | |
var content = cell.defaultContentConfiguration() | |
content.text = "\(item)" | |
cell.contentConfiguration = content | |
cell.trailingSwipeActionsConfiguration = UISwipeActionsConfiguration( | |
actions: [UIContextualAction( | |
style: .destructive, | |
title: "Delete", | |
handler: { [weak self] _, _, completion in | |
guard let self = self else {return} | |
self.snapshot.deleteItems([item]) | |
self.dataSource.apply(self.snapshot, animatingDifferences: false) | |
completion(true) | |
} | |
)] | |
) | |
} | |
let registrationCustomListCell = UICollectionView.CellRegistration<BasicCollectionViewCell, String> { (cell, indexPath, item) in | |
cell.updateWithText(item) | |
(cell as UICollectionViewListCell).trailingSwipeActionsConfiguration = UISwipeActionsConfiguration( | |
actions: [UIContextualAction( | |
style: .destructive, | |
title: "Delete", | |
handler: { [weak self] _, _, completion in | |
guard let self = self else {return} | |
self.snapshot.deleteItems([item]) | |
self.dataSource.apply(self.snapshot, animatingDifferences: false) | |
completion(true) | |
} | |
)] | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment