Skip to content

Instantly share code, notes, and snippets.

@ateliercw
Last active June 10, 2016 03:44
Show Gist options
  • Save ateliercw/928b24103531c0f100e4972734bbb46b to your computer and use it in GitHub Desktop.
Save ateliercw/928b24103531c0f100e4972734bbb46b to your computer and use it in GitHub Desktop.
An un-curried deselect function, for comparison with curried_deselect
extension UIViewController {
func rz_smoothlyDeselectRows(tableView tableView: UITableView?) {
let selectedIndexPaths = tableView?.indexPathsForSelectedRows ?? []
if let coordinator = transitionCoordinator() {
coordinator.animateAlongsideTransitionInView(parentViewController?.view, animation: { context in
selectedIndexPaths.forEach {
tableView?.deselectRowAtIndexPath($0, animated: context.isAnimated())
}
}, completion: { context in
if context.isCancelled() {
selectedIndexPaths.forEach {
tableView?.selectRowAtIndexPath($0, animated: false, scrollPosition: .None)
}
}
})
}
else {
selectedIndexPaths.forEach {
tableView?.deselectRowAtIndexPath($0, animated: false)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment