我们可以在不重新加载的情况下调整UITableViewCell的大小吗?
我们可以在点击其中的按钮时更改UITableViewCell
的内容大小而无需重新加载吗? 当我执行reloadData()
或reloadCell()
UITableView
闪烁,我想避免这种闪烁。
您应该使用beginUpdates()和endUpdates()来更改UITableViewCell的内容大小,在这种情况下,将为tableView中的每个单元调用heightForRowAtindexPath并更新TableviewCell的高度 。 对于iOS> 10 ,您应该更喜欢performBatchUpdates(_:completion 🙂而不是beginUpdates()和endUpdates()。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { self.tableView.beginUpdates() self.tableView.endUpdates() }
了解更多信息
https://appengineer.in/2018/07/11/resize-uitableviewcell-size-without-fluctuation-and-jerk/
https://developer.apple.com/documentation/uikit/uitableview/1614908-beginupdates
如果它只是一个单元格,您可以维护引用并进行必要的更改,并为该tableView
调用beginUpdates()
和endUpdates()
。
或者,如果它是很多单元格,您可以在单元格内部拥有观察者并发布来自另一个来源的通知。 例:
class CustomTableViewCell { init() { // Your initialization NotificationCenter.default.addObserver(self, selector: #selector(resizeCell), name: NSNotification.Name("YourNotificationName"), object: nil) } @objc func resizeCell() { //Your cell layout changes }
然后,每当您为此观察者发布通知时,将调用所需的方法,并且将更新具有此观察者的所有单元格。
NotificationCenter.default.post(name: NSNotification.Name.init("YourNotificationName"), object: nil) tableView.beginUpdates() tableView.endUpdates()
- VIPER-S:编写您自己的体系结构以了解其重要性(第1部分)
- 无法用Xocde 6.4构buildCore-plot
- 如何调整自定义的UITableViewCell nib文件以适应tableView?
- YouTube iFrame API在iPad上播放playVideo()命令后挂起缓冲状态
- iOS 8 AutoLayout滚动视图在iPhone 6 plus上水平滚动
- combobox架模拟器/设备二进制Xcode 7.3
- 使用NSURLConnection上载时,将进度设置为UIProgressView
- 构build设置:我应该在构build设置中做什么更改,以便在发布应用程序时,它将在App Store上显示为仅英语的语言?
- 在向后播放CABasicAnimation后,CALayer消失