Last active
November 14, 2020 05:00
-
-
Save nashysolutions/1feb33edb99da113d958342947b701d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extension MenuViewController: UITableViewDelegate { | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
table.reloadItem(at: indexPath, save: { (item) in | |
switch selections.contains(item) { | |
case true: selections.remove(item) | |
case false: selections.insert(item) | |
} | |
}, animate: false) | |
} | |
} | |
// in table handler | |
func reloadItem(at indexPath: IndexPath, save: (MenuItem) -> Void, animate: Bool = true) { | |
let item = dataSource.itemIdentifier(for: indexPath)! | |
var snapshot = dataSource.snapshot() | |
save(item) | |
snapshot.reloadItems([item]) | |
dataSource.apply(snapshot) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment