Я хотел скрыть статическую ячейку в UITableView, и я сделал это с помощью метода источника данных.Но когда я попытался показать это снова, я не смог.Вот код теста:
var flag = false
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 && flag {
return 0
} else {
return 44
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
cell.frame.size = CGSize(width: cell.frame.width, height: 44.0)
cell.alpha = 1
cell.autoresizingMask = UIView.AutoresizingMask(rawValue: 0)
cell.subviews.first?.frame.size = CGSize(width: cell.subviews.first?.frame.width ?? 0, height: 44.0)
cell.subviews.first?.alpha = 1
cell.subviews.first?.autoresizingMask = UIView.AutoresizingMask(rawValue: 0)
print("\(cell)")
return cell
} else {
return super.tableView(tableView, cellForRowAt: indexPath)
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
flag = !flag
tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
}