ios - 如何控制单元格重定义
问题描述
我有三个部分,第一个存储用户信息,第二个包含添加帖子的字段,第三个是帖子。滚动时,我开始加载添加帖子的部分和帖子部分中的用户信息部分
这是我的代码 UIViewController 扩展 UITableViewDataSource :
func numberOfSections(in tableView: UITableView) -> Int {
presenter?.numberOfSections() ?? 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let section = UserPageTypeSection(rawValue: section) else { return 0 }
return presenter?.numberOfRowsInSection(section: section) ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let section = UserPageTypeSection(rawValue: indexPath.section),
let userInfo = presenter?.cellForRowAt(section: section, indexRow: indexPath.row)
else { return UITableViewCell() }
switch userInfo.type {
case .userInfo:
guard let cell = tableView.dequeueReusableCell(withIdentifier: ProfileInfoTableViewCell.reuseIdentifier, for: indexPath) as? ProfileInfoTableViewCell else { return UITableViewCell() }
cell.userInformation(userData: userInfo.data?[indexPath.row] as? UserProfile)
return cell
case .userAddPost:
guard let cell = tableView.dequeueReusableCell(withIdentifier: ProfileInfoTableViewCell.reuseIdentifier, for: indexPath) as? ProfileInfoTableViewCell else { return UITableViewCell() }
cell.addPostUser()
return cell
case .userPost:
guard let cell = tableView.dequeueReusableCell(withIdentifier: ProfileInfoTableViewCell.reuseIdentifier, for: indexPath) as? ProfileInfoTableViewCell else { return UITableViewCell() }
cell.post(text: "POST")
return cell
default:
return UITableViewCell()
}
解决方案
推荐阅读
- python - AttributeError:在给定的实例中找不到字段“pred_masks”
- python - openAI gym TypeError:无法解压不可迭代的NoneType对象
- javascript - 在 JavaScript 中运行函数后如何回到全局范围?
- visual-studio - 新的 Visual Studio 安装,测试未在测试资源管理器中运行
- dataframe - Pyspark fillna 具有来自另一个数据帧的值
- reactjs - React 告诉我,我不能在 contextAPI 的“Provider”函数中使用钩子
- sql - 从每个 id 具有特定值的表中选择行
- c - 如何将函数的返回值分配给变量
- c# - 以编程方式构建 - 未从程序集中加载“TransformTemplates”任务
- php - 使用 PHP 在 JSON 中搜索值