Search code examples
iosswiftuitableviewuiscrollview

Cell in tableview don't show all the text of label in Swift


I have a TableView in a ScrollView. I set some constraint and auto layout to dynamic cell and dynamic height of table view. But i get some problems with each cell, some of each cell don't show all of content. Any body help?

My information label

And auto layout of number in right of information label

Autolayout of number label

Code of table view

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell.identifier, for: indexPath) as! TableViewCell
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }

Code for dynamic tableview

    override func updateViewConstraints() {
        tableHeightConstraint.constant = tableView.contentSize.height
        super.updateViewConstraints()
    }

My problem now: Result of code

I'm stuck fews day. Many thanks.


Solution

  • There are few things you can do here.

    • Try setting text label's bottom constraint to "Greater than or Equal".
    • Calling layoutIfNeeded() after setting tableView height constraint