ios - UITableViewCell 滚动后被删除
问题描述
我正在尝试创建一个 ToDo 列表应用程序。对于这个应用程序,我需要一个自定义 UITableViewCell。我正在尝试使用我的自定义单元格,但是,当我运行应用程序并尝试滚动表格视图时,所有单元格都会被删除。
这是我的代码:
class ToDoListVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "TodoCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "customCell")
tableView.delegate = self
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return HomeVC.ToDoEvents.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! TodoCell
let eventName = HomeVC.ToDoEvents[indexPath.row].name
let eventTime = HomeVC.ToDoEvents[indexPath.row].time
let completion = HomeVC.ToDoEvents[indexPath.row].isComplete
cell.initialize(task: eventName!, length: eventTime!, completion: completion!)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 70
}
}
我不确定我做错了什么。我经历了其他一些线程,但是,它们都没有解决我的问题。
解决方案
推荐阅读
- c++ - for 循环内的 OpenMP 并行化需要太长时间
- html - 联系我们按钮/smtplib 转发详细信息
- angular - API网关+登录微服务+redis
- javascript - 语义 UI 模式 onOpen/onClose 不起作用
- computer-vision - 使用 PCL 和 RANSAC 进行墙壁检测
- spring-boot - 读取数据时违反约束
- service-worker - Service-Worker 在 Chrome 中保持等待状态
- html - Canvas HTML5 - 绘制图像后更改背景颜色
- c++ - 如何在 C++ 中隐藏 exe dll?
- pandas - 熊猫,创建行并将其组合到我想要的列中