AutoLayout - expanding label but xib view not expanded Swift

Viewed 81

I am using tableView and custom xib to display review comments. I am trying to set tap gesture on comment label so it will expand but for some reason the label expand but not view, even I have set tableview row height to auto dimensions.

How can I set label tap gesture so it will expand label with view. Please anyone can help and identify problem. Thanks I have attached images of the constraints as well.

xib image

constraint

1 Answers

Unfortunately the solution for this is not very nice, and can cause all sorts of issues in the future when you are introducing more and more features into your list.

To get the cell to change, you will need to trigger the layout updates within the table view by calling beginUpdates() and endUpdates(). This means that a cell should have weak reference to the tableView (you can pass it whne setting up the cell in the cellForRow implementation).

class ReviewDetailTableViewCell: UITableViewCell {
    
    weak var tableView: UITableView?

    private func readMore() {
        // Update constrains like you do right now
        tableView?.beginUpdates()
        tableView?.endUpdates()
    }
}

Now everytime you call a method that does the constraint update within the cell, also call the beginUpdates() and endUpdates() methods on the tableView you pass to the cell.

Related