UITableView gets cut off at the bottom / UIScrollView, UITableView, uitableviewdiffabledatasource

13 views Asked by At

i just composed my view like this

enter image description here

I've configured the height of the UITableview so that the height is determined by this code and then applied to the view.

//VC's property
private var tableViewHeightConstraint = NSLayoutConstraint()

public override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        tableViewHeightConstraint.constant
        = busStopTableView.contentSize.height + 122
        print("✅ \(tableViewHeightConstraint.constant)")
    }

// LayoutConstraint
tableViewHeightConstraint = busStopTableView.heightAnchor
            .constraint(equalToConstant: 0)

// LayoutConstraint.activate
NSLayoutConstraint.activate([
    // other things ex) headerView, tableView,
    tableViewHeightConstraint,
    // other things ex) contentView, scrollView 's constraints
])

However, after running the app, when I pull to refresh the scrollview, the bottom of the tableView is cut off.

enter image description here

Can you please send me some keywords to search for this situation?

Why is the height of my tableView variable?

i1) When the scrollView detected the scroll and was lower than the headerview, I tried to use it by setting the scrollView's scroll to false and the tableView's scroll to true.

But there was another side effect, so I decided not to use it.

  1. I tried putting the calculated value of the number of items in the snapshot of diffabledatasource and the height of the tableView cell, but when I pull to refresh the same, the height value of the tableView changes. Same thing.

  2. The method of applying the height of the tableView when the snapshot is applied does not draw the tableView completely in the first place.

0

There are 0 answers