The problem with this code (inside func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath))
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
if indexPath.row > 1{
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row-1, inSection: 0)], withRowAnimation: .None)
}
if tDate[activeRow].count == 0{
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .None)
}
is that both reloadRowsAtIndexPaths are animated, although withRowAnimation: .None is specified. What am I missing here?
It is often the case in iOS
and OS X
that you end up with an implicit animation for one reason or another (for example, the code is being executed by other code that has already triggered animation).
It can be especially difficult to control animations with UITableView
and UICollectionView
in my experience. Your best bet is probably to put the calls to reloadRowsAtIndexPaths:withRowAnimation:
into a closure passed to UIView
's performWithoutAnimations:
method:
UIView.performWithoutAnimation {
if indexPath.row > 1{
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row-1, inSection: 0)], withRowAnimation: .None)
}
if tDate[activeRow].count == 0{
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .None)
}
}
Note: It's also not a bad idea to call tableView.beginUpdates()
and tableView.endUpdates()
before and after multiple updates that happen all at once.
While an appropriate solution for this problem was described by Charles, it did not answer the question as to why UITableViewRowAnimation.none
provides an animation.
According to the docs for UITableViewRowAnimation.none
, "The inserted or deleted rows use the default animations." Therefore, while .none
sounds like there shouldn't be an animation, it actually acts more like .automatic
.
I would have left this as a comment, but comments cannot contain pictures. Please note that this answer is not meant to solve the problem as Charles has already done that. This is strictly for reference for the next person wondering why UITableViewRowAnimation.none
provides an animation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With