【发布时间】:2017-12-06 13:49:08
【问题描述】:
我有一个表格视图,其中每个单元格都有一个标签。此标签的数据源来自 firebase api。现在,最初标签以完美的形式加载。当您滚动浏览时,如果任何标签的文本宽度较短,则单元格的其余部分将其标签更改为此大小。
我什至尝试在它周围应用堆栈视图,但我帮不上什么忙
下面是cellForRow的代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let post = posts[indexPath.row]
if let cell = tableView.dequeueReusableCell(withIdentifier: "FeedCell", for: indexPath) as? FeedCell {
cell.caption.text = ""
cell.configureCell(post: post)
cell.caption.sizeToFit()
cell.delegate = self
return cell
} else {
return FeedCell()
}
}
TableviewCell 中的函数代码
func configureCell(post: Posts, img: UIImage? = nil) {
self.posts = post
self.caption.text = posts.caption
}
我真的无法解决这个问题。非常感谢任何帮助。
【问题讨论】:
-
来自这个答案:stackoverflow.com/a/20043138/442121你应该取消选中使用自动布局或尝试另一个答案对你有用
-
谢谢,这是一个很好的修复。但我已经有一个正在生产的应用程序。删除自动布局意味着调整大部分内容。我尝试过这个。许多事情在视觉上完全出错了。有没有其他办法
标签: ios swift uitableview uilabel