How to get content size of UITableView in runtime?

233 Views Asked by At

I'm trying to get the content size of UITableView in runtime, where I working on library that will do some moves when pop over the views and to do this I wrote this code inside the library to figure out that inside the presented view will be UITableView:

if view.isKind(of: UIView.self) {
            for subView in view.subviews {
                for sv in subView.subviews {
                    if sv.isKind(of: UITableView.self) {
                        print(sv.frame.size.height)

Here I got the table view, but I couldn't get the contentSize property

                        print("table view found")
                    }
                }
            }
        }

Any tips how to get its content size ?!

1

There are 1 best solutions below

0
Phillip Mills On BEST ANSWER

Use a cast instead of a test so that the compiler knows the object's properties:

if view.isKind(of: UIView.self) {
    for subView in view.subviews {
        for sv in subView.subviews {
            if let tableView = sv as? UITableView {
                print(tableView.contentSize.height)
            }
        }
    }
}