Austin Erck Austin Erck - 5 months ago 7
Swift Question

Get Height of Table Contents in Swift

I'm trying to get the height of all of a table's contents so I can update the container it is in. This will allow the container and other views in the scroll view to scroll together.

Answer

Swift 2.2

func tableViewHeight() -> CGFloat {
    tableView.layoutIfNeeded()

    return tableView.contentSize.height
}

Objective-C

- (CGFloat)tableViewHeight {
    [tableView layoutIfNeeded];

    return [tableView contentSize].height;
}
Comments