Created
May 23, 2016 12:18
-
-
Save AndreyPanov/45939e5f2a2304eb85be4a335f993617 to your computer and use it in GitHub Desktop.
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
extension UITableView { | |
func animatedInsert(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) { | |
guard paths.isEmpty == false else { return } | |
beginUpdates() | |
insertRowsAtIndexPaths(paths, withRowAnimation: animation) | |
endUpdates() | |
} | |
func animatedlReload(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) { | |
guard paths.isEmpty == false else { return } | |
beginUpdates() | |
reloadRowsAtIndexPaths(paths, withRowAnimation: animation) | |
endUpdates() | |
} | |
func animatedMove(indexPaths fromPaths: [NSIndexPath], toIndexPaths toPaths: [NSIndexPath]) { | |
guard fromPaths.count > 0 else { return } | |
guard fromPaths.count == toPaths.count else { | |
assert(false, "Passing different amount of start and end index path possitions") | |
return | |
} | |
beginUpdates() | |
for (index, path) in fromPaths.enumerate() { | |
moveRowAtIndexPath(path, toIndexPath: toPaths[index]) | |
} | |
endUpdates() | |
} | |
func animatedDelete(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) { | |
guard paths.isEmpty == false else { return } | |
beginUpdates() | |
deleteRowsAtIndexPaths(paths, withRowAnimation: animation) | |
endUpdates() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment