Tableview单元格可重用性,剪切标签文本

时间:2017-11-30 08:31:50

标签: ios swift uitableview autolayout

Here I attached the gif file. Refer this

在我的tableview中,我有一个带自动布局的自定义xib单元格。当我运行项目时,得到的问题就像gif文件一样。

我的tableview函数

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!

} 

1 个答案:

答案 0 :(得分:0)

最后我找到了答案。只需在cellForRowAt索引路径

中添加单元格?.layoutIfNeeded()
cell?.layoutIfNeeded()