Search code examples
iosswiftuitableviewautolayout

Tableview cell reusability, cutting label texts


Here I attached the gif file. Refer this

In my tableview I have a custom xib cell with autolayout. When I run the project, getting the problem like the gif file.

Its my tableview function

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "requestsCell", for: indexPath) as? RequestsTableViewCell
    cell?.backgroundColor = .clear

    let passengerName = cell?.viewWithTag(1) as! UILabel
    let bookingCreator = cell?.viewWithTag(2) as! UILabel
    let department = cell?.viewWithTag(3) as! UILabel
    let product = cell?.viewWithTag(4) as! UILabel
    passengerName.text = "Muhammed yasheed"
    bookingCreator.text = "Muhammed Yasheed"
    department.text = "Programming"
    product.text = "Flight"


    cell?.approvedView.isHidden = false
    cell?.cancelView.isHidden = true



    return cell!

} 

Solution

  • Finally I found the answer. Just add cell?.layoutIfNeeded() in cellForRowAt indexpath

    cell?.layoutIfNeeded()