首页 > 解决方案 > 部分滑动单元格后,表格视图单元格高度缩小

问题描述

使用 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

标签: iosswift

解决方案


尝试这个:

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为单元格内的标签提供了适当的 ( ) 约束。


推荐阅读