Skip to content

Instantly share code, notes, and snippets.

@JoeFerrucci
Last active July 21, 2016 23:07
Show Gist options
  • Save JoeFerrucci/4004cad427bead3f7eff8050bfd5aad2 to your computer and use it in GitHub Desktop.
Save JoeFerrucci/4004cad427bead3f7eff8050bfd5aad2 to your computer and use it in GitHub Desktop.
Finding the height of your UITableView's current content.
/////////////////////////////////////////////////////////////////////
// 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