Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active January 19, 2019 14:55
Show Gist options
  • Save KentarouKanno/41d79551e2cbb92300ec29fc812bc166 to your computer and use it in GitHub Desktop.
Save KentarouKanno/41d79551e2cbb92300ec29fc812bc166 to your computer and use it in GitHub Desktop.
extension UITableView {
    
    func reloadData(completion: @escaping () -> Void) {
        UIView.animate(withDuration: 0, animations: {
            self.reloadData()
        }) { _ in
            completion()
        }
    }
    
    func insertRows(indexPaths: [IndexPath],
                    animation: UITableViewRowAnimation = .automatic,
                    completion: @escaping () -> Void) {
        UIView.animate(withDuration: 0, animations: {
            insertRows(at: indexPaths, with: animation)
        }) { _ in
            completion()
        }
    }
    
    func deleteRows(indexPaths: [IndexPath],
                    animation: UITableViewRowAnimation = .automatic,
                    completion: @escaping () -> Void) {
        UIView.animate(withDuration: 0, animations: {
            deleteRows(at: indexPaths, with: animation)
        }) { _ in
            completion()
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment