ios - UITableView 分隔符在以编程方式设置时消失
问题描述
我试图在部分中隐藏最后一个单元格和单个单元格的分隔符。我的方法 cellForRow 如下所示:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self), for: indexPath)
if dataSource.count - 1 == indexPath.row {
cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: .greatestFiniteMagnitude)
} else {
cell.separatorInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
}
return cell
}
它可以工作,但在某些情况下,当 else 块执行时,分隔符仍然不可见。它发生在最后一个单元格重用于中间单元格时,但我不明白为什么不应用更新的分隔符插图。这个问题的原因可能是什么?
解决方案
推荐阅读
- node.js - 节点 https ssl 你的连接不是私人错误
- powershell - 从 Windows 托盘生成 PowerShell 管理控制台
- php - openweather unix datetimestamp to local datetime in php
- javascript - Selenium 点击每个 html 一个标签
- terraform - 使用 Terraform 在 Azure 应用程序洞察 Web 测试中创建警报
- reactjs - 如何将 json 正文添加到我的 axios 发布请求中?
- excel - 循环浏览文件夹中的文件,如果语句为假一次,代码会中断
- excel - 如何在公式中使用字符串?
- azure - 如何使用 Azure DevOps 将 Asp.net Web 表单网站部署到 Azure Web App 服务?
- javascript - 对象已排序,但未使用 lodash sortBy 保留其键