在两个Uilabels中,我都设置为0的行数,以使其成为多行,并将两者添加到这两个上,如下所示:
preferredmaxLayoutWidth
根据其他stackoverflow建议,我在
cell.questionLabel.preferredMaxLayoutWidth = cell.questionLabel.frame.width
cell.answerLabel.preferredMaxLayoutWidth = cell.answerLabel.frame.width
viewDidLoad()
在第一次加载时,即使线设置为0,并且在标签不一致的位置奇怪的是,标签仍在截断。但是,当将屏幕向下滚动然后返回到顶部时,标签自动校正自己,布局非常完美。请参阅下面的屏幕截图:以前有人遇到过这个问题,如果可以的话,您可以将我指向正确的方向。我不确定这是我未能设置的东西,还是我的自动布局约束的问题。
self.faqTableView.rowHeight = UITableViewAutomaticDimension
self.faqTableView.estimatedRowHeight = 140.00
将Uilabel的行数设置为零,并实现以下方法
cell.questionLabel.preferredMaxLayoutWidth = cell.questionLabel.frame.width
cell.answerLabel.preferredMaxLayoutWidth = cell.answerLabel.frame.width
self.faqTableView.estimatedRowHeight = 140.00
示例(解决方案):
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
示例(问题):
func configureForCell(message: Messages) {
let auth = message.auth
let authRef = db.collection("Users").document(auth)
authRef.getDocument { document, error in
if let error = error {
print("Error fetching document: \(error.localizedDescription)")
return
}
guard let document = document, document.exists,
let data = document.data(),
let name = data["name"] as? String,
let imageUrl = data["img"] as? String else {
return
}
self.nameLabel.text = name
self.thumbnail.loadImageUsingCacheWithUrlString(urlString: imageUrl)
}
self.textLabel.text = message.text // Populating your label ensures it happens on the main thread and the character count is considered on initial view load
}