Get height of UITableView without scroll bars
Obligatory Swift 3.0 & 2.2 answer.
var tableViewHeight: CGFloat {
tableView.layoutIfNeeded()
return tableView.contentSize.height
}
Try the contentSize
method, which is inherited from UITableView’s superclass, UIScrollView. However, you may find that contentSize
returns an incorrect or out of date value, so you should probably call layoutIfNeeded
first to recalculate the table’s layout.
- (CGFloat)tableViewHeight
{
[tableView layoutIfNeeded];
return [tableView contentSize].height;
}