UITableViewCell大小在运行时未扩展。?

问题描述 投票:1回答:2

[here is a storyboard image. i have take a dynamic tableviewcell 我尝试通过拖放UITableViewCell并从情节提要中更改行高,它无法在运行时扩展像元高度。

Xcode 9.0.1Swift 4中,我面临的问题是,在运行时单元格高度没有增加。因此,请帮助我解决此问题。

enter image description here

enter image description here

ios swift uitableview tableview row-height
2个回答
6
投票

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

  • 分配并实现数据源和委托
  • UITableViewAutomaticDimension分配给rowHeight和估计的RowHeight
  • 实现委托/数据源方法(即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
}

对于UITableviewCell中的标签实例

  • 设置行数= 0(&换行模式=截尾)
  • 相对于其superview /单元容器设置所有约束(上,下,左左)。>>
  • [可选
  • :设置标签的最小高度,如果您希望标签覆盖最小的垂直区域,即使没有数据也是如此。

    << img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9UMzU0cy5wbmcifQ==” alt =“在此处输入图像描述”>


2
投票

尝试一下:

© www.soinside.com 2019 - 2024. All rights reserved.