我正在使用 UITableViewDataSourcePrefetching 进行分页。
这些值将从领域本地存储中获取。
我将得到一个对象数组。这些值将应用于现有的 UITableViewDiffableDataSource 数据源。
应用快照后,表格视图滚动到顶部。
我已经验证我的所有 ChatMessage 对象都具有唯一的 hashValues。
如何防止滚动?
视频链接TableView_scroll_issue_video
鉴于我的代码片段
private func appendLocal(chats chatMessages: [ChatMessage]) {
var sections: [String] = chatMessages.map({ $0.chatDateTime.toString() })
sections.removeDuplicates()
guard !sections.isEmpty else { return }
var snapshot = dataSource.snapshot()
let chatSections = snapshot.sectionIdentifiers
sections.forEach { section in
let messages = chatMessages.filter({ $0.chatDateTime.toString() == section })
/// Checking the section is already exists in the dataSource
if let index = chatSections.firstIndex(of: section) {
let indexPath = IndexPath(row: 0, section: index) …
Run Code Online (Sandbox Code Playgroud) uitableview ios swift diffabledatasource uitableviewdiffabledatasource
上面的是我的内心细胞。我想将此单元格加载到下面的单元格中。内部单元的数量是动态的。
上面的是我的主要单元格。红色部分是UIView。我想将一些innerCell动态地添加到UIView中。我尝试了以下代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let mainCell = tableView.dequeueReusableCell(withIdentifier: "FlightCellMain", for: indexPath) as? FlightCellMain
let innerCell = tableView.dequeueReusableCell(withIdentifier: "FlightCell", for: indexPath) as? FlightCell
mainCell?.flightCellView.addSubview(innerCell!)
mainCell?.backgroundColor = .clear
innerCell?.backgroundColor = .clear
// innerCell?.innerCellWidthConst.constant = (mainCell?.mainView.frame.width)!
self.showStopsView(2, self.airportlist, (innerCell?.leftRound)!, (innerCell?.rightRound)!, (innerCell?.centerLine)!, (innerCell?.routeView)!)
mainCell?.flightCellViewHieghtConst.constant = (mainCell?.flightCellViewHieghtConst.constant)! + 125
innerCell?.layoutIfNeeded()
mainCell?.layoutIfNeeded()
return mainCell!
}
Run Code Online (Sandbox Code Playgroud)
但是结果就是这样。我提供了自动布局。当我分别运行两个单元格时,它适合其内容。我在做什么错?
上面的图片是我试图实现的模型。航班数量详细信息是动态的。