[here is a storyboard image. i have take a dynamic tableviewcell 我尝试通过拖放UITableViewCell
并从情节提要中更改行高,它无法在运行时扩展像元高度。
在Xcode 9.0.1
和Swift 4
中,我面临的问题是,在运行时单元格高度没有增加。因此,请帮助我解决此问题。
要为行高和估计的行高设置自动尺寸,请确保执行以下步骤,自动尺寸对单元格/行高的布局有效。
UITableViewAutomaticDimension
分配给rowHeight和估计的RowHeightheightForRowAt
并向其返回值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中的标签实例
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9UMzU0cy5wbmcifQ==” alt =“在此处输入图像描述”>
尝试一下: