Xcode 9.0.1中的UITableView Swift 4单元格大小在运行时没有扩展.

Yog*_*tel 1 row-height uitableview tableview ios swift

这是一个故事板图像.我已经尝试了一个动态的tableviewcell我已经尝试过拖放并UITableViewCell从故事板中更改行高,它不能在运行时扩展单元格高度.

Xcode 9.0.1Swift 4,我面临的问题是细胞高度在运行时没有增加.所以,请帮助我解决这个问题.

在此输入图像描述

在此输入图像描述

Kru*_*nal 6

要设置行高和估计行高的自动尺寸,请确保执行以下步骤,自动尺寸对单元格/行高度布局有效.

  • 分配和实现dataSource和委托
  • 分配UITableViewAutomaticDimension给rowHeight和estimatedRowHeight
  • 实现delegate/dataSource方法(即heightForRowAt返回一个值UITableViewAutomaticDimension)

-

@IBOutlet weak var table: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Don't forget to set dataSource and delegate for table
    table.dataSource = self
    table.delegate = self

    // Set automatic dimensions for row height
    table.rowHeight = UITableViewAutomaticDimension
    table.estimatedRowHeight = UITableViewAutomaticDimension
}



// UITableViewAutomaticDimension calculates height of label contents/text
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}
Run Code Online (Sandbox Code Playgroud)

对于UITableviewCell中的标签实例

  • 设置行数= 0(&换行模式=截断尾部)
  • 设置相对于其superview/cell容器的所有约束(顶部,底部,右侧).
  • 可选:如果您希望标签覆盖最小垂直区域,即使没有数据,也可以设置标签的最小高度.

在此输入图像描述

  • 谢谢.现在正在工作!! (4认同)