ios - 提高具有非统一内容的 `UITableViewCell` 的性能
问题描述
我有一个UITableView
其单元格包含动态内容。
假设可能有三种类型的单元格内容(实际上,还有更多)。
Type1
: 3 个UILabel
堆叠在一起
Type2
: 2 个UIButtons
并排堆叠
Type3
: 1UISlider
我是中心
我有这些 UI 元素的类。
在我的cellForRowAtIndexPath
中,我将这些添加到contentView
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellID)!
cell.contentView.subviews.forEach { $0.removeFromSuperview() } // Remove everything before adding new stuff
cell.contentView.addSubview(Type3()) // Pretend there's logic here to decide whether to use Type1, Type2, or Type3
return cell
}
这目前有效,但显然非常hacky且不优雅。我该怎么办?
解决方案
推荐阅读
- python - 如何使用带有 appId 和 processId 异常的 appium 和 python 定位打开的应用程序窗口?
- sql - 在事件发生后的当天找到每种事件类型的平均值
- python - PushShift:从时间范围内抓取提交
- javascript - 之后添加 html-element 的动态函数调用
- javascript - 在 Angular + AngularFire 应用程序中登录后权限被拒绝
- angular - 带有角度 6 的 Smilesdrawer 未渲染(由于项目条件无法升级)
- css - Css - 当我点击它时如何让我的按钮产生点击效果
- memory - 不同集合实现的时间复杂度和内存需求
- java - Redisson解码随机类强制转换异常
- javascript - 在 DataTables 中使用的 HTML 下拉列表值以按它们排序