Last active
July 21, 2016 23:07
-
-
Save JoeFerrucci/4004cad427bead3f7eff8050bfd5aad2 to your computer and use it in GitHub Desktop.
Finding the height of your UITableView's current content.
This file contains 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
///////////////////////////////////////////////////////////////////// | |
// finding the height of your UITableView's current content: | |
///////////////////////////////////////////////////////////////////// | |
let tableView = UITableView() | |
func contentHeight(forTableView tableView: UITableView) -> CGFloat { | |
let lastSectionIndex = tableView.numberOfSections - 1 | |
let lastRowIndex = tableView.numberOfRowsInSection(lastSectionIndex) | |
let indexPath = NSIndexPath(forRow: lastRowIndex, inSection: lastSectionIndex) | |
let lastRowRect = tableView.rectForRowAtIndexPath(indexPath) | |
// tableView's contentHeight | |
let contentHeight = lastRowRect.origin.y + lastRowRect.size.height | |
return contentHeight | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment