Created
August 17, 2014 06:12
-
-
Save nvkiet/e40b5b49fa3fd3c1952c to your computer and use it in GitHub Desktop.
Keep uitableview static when inserting rows at the top
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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