Per una soluzione di animazione a impatto morbido:
Swift 3:
let indexPath = IndexPath(item: row, section: 0)
tableView.reloadRows(at: [indexPath], with: .fade)
Swift 2.x:
let indexPath = NSIndexPath(forRow: row, inSection: 0)
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
Questo è un altro modo per proteggere l'app dall'arresto anomalo:
Swift 3:
let indexPath = IndexPath(item: row, section: 0)
if let visibleIndexPaths = tableView.indexPathsForVisibleRows?.index(of: indexPath as IndexPath) {
if visibleIndexPaths != NSNotFound {
tableView.reloadRows(at: [indexPath], with: .fade)
}
}
Swift 2.x:
let indexPath = NSIndexPath(forRow: row, inSection: 0)
if let visibleIndexPaths = tableView.indexPathsForVisibleRows?.indexOf(indexPath) {
if visibleIndexPaths != NSNotFound {
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}