swift - 调用 Firebase 后自行调整单元格大小
问题描述
我正在构建一个表格视图,我正在加载不同大小的文本并希望单元格是动态的。当我不先调用数据库时,这非常简单。我知道我正确地使用了约束,因为当我没有调用数据库并且只是创建了一个数组时,我让单元格正常运行。我可以让它工作的唯一方法是在 viewDidLoad() 中调用我的函数来获取数据,然后在闭包中重新加载 tableview。然后在 vewDidAppear 中,我再次重新加载 tableView。这可行,但从用户体验方面来看似乎很难看,因为文本加载一次,然后调整大小。还有其他我不知道的方法吗?先感谢您!
这是我的 viewDidLoad() 和 viewDidAppear() 这个控制器中的所有其他内容都是非常基本的。
override func viewDidLoad() {
super.viewDidLoad()
setupNavigationBarItems()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
commentTextView.delegate = self
formatter.timeZone = TimeZone.current
formatter.dateFormat = "yyyy-MM-dd HH:mm"
tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableView.automaticDimension
comment.getComments(roundID: roundID) {
self.tableView.reloadData()
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.tableView.reloadData()
}
解决方案
推荐阅读
- c - Sprite Packing C 应用程序中的 Sprite 对齐
- javascript - 如果分配给不存在的 vue 数据属性,如何显示某种错误或警告?
- sql - 如何将时间偏移转换为 Int 或添加到日期时间列(使用 TSQL)
- c# - 在条件下更改 DevExpress GridView 上的行背景颜色
- php - MySQL插入不接受十进制值
- ksqldb - KSQL 每组选择一行对应于具有最小时间戳的行
- swift - 有没有办法将任何大小写与 Swift 枚举中的参数匹配?
- xamarin - Xamarin 将图像添加到导航栏
- python - 如何在 Python 中使用标题转换数据框中的摘要输出?
- c# - 在 C# 中查找列表中的项目连续重复多少次的最佳方法?