Skip to content

Instantly share code, notes, and snippets.

@nvkiet
Created August 17, 2014 06:12
Show Gist options
  • Save nvkiet/e40b5b49fa3fd3c1952c to your computer and use it in GitHub Desktop.
Save nvkiet/e40b5b49fa3fd3c1952c to your computer and use it in GitHub Desktop.
Keep uitableview static when inserting rows at the top
private func addListBubbleCellsWithCount(count: Int) {
var contentOffset = self.tableView.contentOffset
UIView.setAnimationsEnabled(false)
var indexPaths = [NSIndexPath]()
var heightForNewRows: CGFloat = 0
for var i = 0; i < count; i++ {
let indexPath = NSIndexPath(forRow: i, inSection: 0)
indexPaths.append(indexPath)
heightForNewRows += heightForCellAtIndexPath(indexPath)
}
contentOffset.y += heightForNewRows
tableView.beginUpdates()
tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.None)
tableView.endUpdates()
UIView.setAnimationsEnabled(true)
self.tableView.setContentOffset(contentOffset, animated: false)
}
private func heightForCellAtIndexPath(indexPath: NSIndexPath) -> CGFloat {
let messageData = messagesDataArray[indexPath.row]
return LINBubbleCell.getHeighWithMessageData(messageData)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment