【发布时间】:2018-02-06 07:28:51
【问题描述】:
问题是当我第一次启动时它需要高度(从顶部和底部)。但是当向上和向下滚动时,额外的高度被删除。我无法理解为什么会出现这个问题。
控制器代码
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 的约束
【问题讨论】:
-
向我们展示所有这些组件的约束。
-
给你的每个标签一个不同且可见的背景颜色,它可能只是提示出了什么问题
-
第二行发生了什么?
-
请检查我更新的问题
-
从底部标签移除底部约束,这是额外的,如果你希望你的标签随文本一起增长,不要给它底部约束并根据标签大小计算你的单元格的高度。
标签: ios swift xcode autolayout