I use
func insertRowsAtIndexPaths(indexPaths: [NSIndexPath],
withRowAnimation animation: UITableViewRowAnimation)
method to insert a new Ro
func insertRowsAtIndexPaths(indexPaths: [NSIndexPath],
withRowAnimation animation: UITableViewRowAnimation)
It is the method for appending the rows. For inserting rows at bottom you need to give indexpath of the last row.
For Example:
var IndexPathOfLastRow = NSIndexPath(forRow: self.array.count - 1, inSection: 0)
self.tableView.insertRowsAtIndexPaths([IndexPathOfLastRow], withRowAnimation: UITableViewRowAnimation.Left)
Did you try using UITableViewRowAnimationBottom
as the row animation parameter?
Like so: (in swift)
tableView.insertRowsAtIndexPaths([indexPath],
withRowAnimation: UITableViewRowAnimation.Bottom)
Or Objective-C:
[self insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationBottom];
Swift 3
TableView.beginUpdates()
let indexPath:IndexPath = IndexPath(row:(self.yourArray.count - 1), section:0)
TableView.insertRows(at: [indexPath], with: .left)
TableView.endUpdates()
TableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
Thanks @raf for the suggestion:
What you need to do then, is animate the whole UITableView
in it's parent view up as you insert elements. If you're using autolayout
, capture the Top constraint in a property, and change it's constant
as you insert elements. Something like:
topConstraint.constant = newValue
UIView.animateWithDuration(0.5, animations: {
self.layoutIfNeeded()
})