[英]UITableView lags when scrolling with multiple cell types
我知道有关此主题的问题很多,但请耐心等待,因为我没有找到针对自己特定问题的解决方案。
首先,我的整个应用程序都在代码中(没有情节提要)。 我正在创建具有多种单元格类型的tableView(从后端从那里获取数据)。 单元格处于恒定顺序,这意味着第一个单元格将与其他任何第一个单元格始终具有相同的类型(不确定您是否明白我的意思,但是从技术上讲,这些单元格类型对于特定的indexPath是恒定的。
所以问题是我有一些方法可以使每个indexPath的特定单元出队。 在我的一个单元格中,我有一个MapboxStatic地图,该地图从Mapbox的服务器返回地图的图像。 假设在初始运行时该单元格不在屏幕上,如果我滚动得足够快,tableView将延迟一秒钟左右以加载返回的图像(我尝试在不做任何更改的情况下在主队列上异步加载它)。
现在,我的另一个问题是使用UberRides按钮,滚动时它也滞后了(同一问题)。
值得一提的是,如果我在tableView中滚动一次(有滞后),然后上下滚动它不再滞后,但我想这是因为出队的单元格仍在内存中。
如果您需要任何其他详细信息,请发表评论。
[编辑]代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 1 {
return reserveTableViewCell(at: indexPath)
} else if indexPath.section == 2 {
return dateTimeTableViewCell(at: indexPath)
} else if indexPath.section == 3 {
return descriptionTableViewCell(at: indexPath)
} else if indexPath.section == 4 {
if indexPath.row == 0 {
return mapTableViewCell(at: indexPath)
} else {
return uberTableViewCell(at: indexPath)
}
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: defaultCell, for: indexPath)
return cell
}
}
private func reserveTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reserveCell, for: indexPath) as! ReserveTableViewCell
return cell
}
private func descriptionTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: descriptionCell, for: indexPath) as! DescriptionTableViewCell
return cell
}
private func dateTimeTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: dateTimeCell, for: indexPath) as! DateTimeTableViewCell
return cell
}
private func mapTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: mapCell) as! MapTableViewCell
cell.detailController = self
return cell
}
private func uberTableViewCell(at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: uberCell, for: indexPath) as! UberTableViewCell
return cell
}
最好
好吧,创建单元很慢。 现在知道要花多少时间很难给您任何建议。 使用时间分析器确定有问题的代码。
如果不需要覆盖,则可以尝试使用MGLMapSnapshotter
。 这是一个如何将MGLMapSnapshot与表视图一起使用的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.