【问题标题】:Table View Cell Height Shrinks After Partial Swipe of Cell部分滑动单元格后,表格视图单元格高度缩小
【发布时间】:2021-04-24 05:22:50
【问题描述】:

使用 SwipeCellKit 的表格视图控制器

使用设置行高

cell.textLabel?.numberOfLines = 0 //allows row size to expand
cell.textLabel?.lineBreakMode = .byWordWrapping

也试过了:

tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight =  UITableView.automaticDimension

当我打开 tableviewcontroller 时,单元格高度是正确的。 当我向左滑动但再次单击时决定不删除单元格时,单元格大小将缩小为两行。 如果我离开表格视图控制器并回来,单元格高度再次正确。

视频示例:https://drive.google.com/file/d/1tbJb0XrrjWQ3An-bc_XdZfPPNLg6tXlD/view?usp=sharing

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    试试这个:

    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 270
    

    estimatedRowHeight一个更高的值,而不是使用UITableView.automaticDimension

    将下表视图委托方法添加到您的代码中:

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableView.automaticDimension
    

    }

     override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
      return UITableView.automaticDimension
    

    }

    希望您在情节提要中为单元格内的标签提供了适当的 (top, bottom, leading and trailing) 约束。

    【讨论】:

    • 感谢您的反馈,不幸的是没有工作.... 最终删除 SwipeCellKit 并自己创建滑动操作,这已经解决了问题。