【发布时间】:2017-11-10 21:41:00
【问题描述】:
在发布此之前,我已经阅读了一些类似 this 或 this 的文章,但所有这些示例都始终使用动态数据。我想知道如何在静态数据中实现可扩展的表格视图。我认为这更简单,但我不知道。我的 sn-p 代码:
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if (indexPath.section == 1) {
if indexPath.row == self.department {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
}
if indexPath.section == 0 {
if indexPath.row == 2 {
datePickerFrom.isHidden = true
}
else if indexPath.row == 4 {
datePickerUntil.isHidden = true
}
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
if indexPath.section == 1 {
let lastDepartment = self.department
self.department = indexPath.row
tableView.reloadRows(at: [indexPath, IndexPath.init(row: lastDepartment, section: 1)], with: .none)
}
if indexPath.section == 0 {
if indexPath.row == 2 {
datePickerFrom.isHidden = false
}
else if indexPath.row == 4 {
datePickerUntil.isHidden = false
}
tableView.reloadData()
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var count = 0
if section == 0 {
} else if section == 1 {
count = 2
} else if section == 2 || section == 3 {
count = 1
}
return count
}
假设我有 4 个部分。我想让第一部分可扩展,但包含静态表格、单元格和静态数据。
【问题讨论】:
标签: swift uitableview expand