Я искал в сети свою проблему, но в моем случае ничего не помогло.Это что-то особенное.
Мое приложение имеет функцию контрольного списка, все работает нормально, но есть эта проблема.При добавлении checkmark
на UITableViewCell
и удалении одной из других ячеек после этого.Все checkmarks
будут удалены.
Я думал, что у массива и соединения возникают проблемы, когда что-то удаляется.Я имею в виду «порядок» свойств в массиве.Я спросил своих коллег (ИТ), но никто не мог мне помочь.
class ViewControllerChecklist: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var myTableView: UITableView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (checklist.count)
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.textColor = UIColor(red: 4 / 255.0, green: 59 / 255.0, blue: 101 / 255.0, alpha: 1.0)
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 18.0)
cell.textLabel?.text = checklist[indexPath.row]
return cell
}
// checkmarks when tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
tableView.deselectRow(at: indexPath, animated: true)
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
checklist.remove(at: indexPath.row)
myTableView.reloadData()
}
}
override func viewDidAppear(_ animated: Bool) {
myTableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
UITableViewCell.appearance().tintColor = UIColor(red: 237 / 255.0, green: 108 / 255.0, blue: 4 / 255.0, alpha: 1.0)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Ячейки выбраны
Нажав удалить
Ячейка удалена