gpt4 book ai didi

ios - 标签从上到下有额外的空间吗?

转载 作者:行者123 更新时间:2023-11-30 11:47:45 25 4
gpt4 key购买 nike

我在下面创建了一个自定义单元格,如下所示。 enter image description here

问题是当我第一次启动时,它需要高度(从顶部和底部开始)。但是当向上和向下滚动时,额外的高度会被删除。我无法理解为什么会发生这个问题。

顶部标签的行号是固定的。第二个标签的行号为 0。 enter image description here

Controller 代码

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {

return UITableViewAutomaticDimension
}

func numberOfSections(in tableView: UITableView) -> Int {

return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return 15
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell:SampleCell = tableView.dequeueReusableCell(withIdentifier: "SampleCell") as! SampleCell
if indexPath.row == 0 {
cell.labelDescription.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.f Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.f Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.f Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like "

} else {
cell.labelDescription.text = "skdfjksj gkfjg"
}
tableView.sizeToFit()
return cell
}

UIImage 的约束

enter image description here

顶级 UILabel 的约束 enter image description here

底部 UILabel 的约束 enter image description here

最佳答案

UITableViewAutomaticDimension设置为heightForRowAt

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

UILabelnumberOfLine设置为0& 设置前导尾随顶部底部约束

关于ios - 标签从上到下有额外的空间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48637638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com