Прямо сейчас у меня есть два раздела в табличном представлении, и когда выбрана определенная строка, она перемещается в другой раздел. Есть ли способ отобразить сообщение, такое как «представление пусто», когда ни одна ячейка не занимает раздел, а затем, когда ячейка действительно занимает раздел, сообщение очищается?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var goalTableView: UITableView!
let sections: [String] = ["Mark as Complete:", "History:"]
var goals: [[String]] = [["goal 1", "goal 2", "goal 3"], []]
override func viewDidLoad() {
super.viewDidLoad()
let headerView = UIView()
goalTableView.tableHeaderView = headerView
headerView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 5)
}
}
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return goals[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TodayGoalViewCell_1", for: indexPath) as? GoalTableViewCell
cell?.goalLabel.text = goals[indexPath.section][indexPath.row]
cell?.cellDelegate = self
cell?.index = indexPath
return cell!
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return goals.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
progressBarAnimation()
if indexPath.section == 0 {
goals[1].append(goals[0][indexPath.row])
goals[0].remove(at: indexPath.row)
tableView.reloadData()
}
}
}
extension ViewController: GoalTableView {
func selectGoalButton(index: Int) {
}
}