Created a table of three sections, added a click checkmarker. I can not remove the duplication checkmarker in the table on the following cells from the clicked.

import UIKit class AllExersiseTableViewController: UITableViewController { //создаем секции struct Objects { var sectionName: String! var sectionObjects: [(name: String, image:String)]! } var objectsArray = [Objects]() //создаем масив с ячейками для предотвращения дублирования чекмаркеров в таблице по нажатию var allExersiseTable = [Bool](count: 15, repeatedValue: false) override func viewDidLoad() { super.viewDidLoad() objectsArray = [Objects(sectionName: "Standing", sectionObjects: [(name: "Приседания", image:"bb"), (name: "Отжимания", image:"bt"), (name: "Подтягивания", image:"ca"), (name: "Прыжки", image:"co"), (name: "Бег", image:"de")]), Objects(sectionName: "Sitting", sectionObjects: [(name: "БЕГ", image:"ru"), (name: "ПРЫЖКИ", image:"al"), (name: "ПРИСЕДАНИЯ", image:"au"), (name: "ОТЖИМАНИЯ", image:"es"), (name: "ТОЛЧЕК", image:"fr")]), Objects(sectionName: "Special", sectionObjects: [(name: "БЕГ", image:"ru"), (name: "ПРЫЖКИ", image:"al"), (name: "ПРИСЕДАНИЯ", image:"au"), (name: "ОТЖИМАНИЯ", image:"es"), (name: "ТОЛЧЕК", image:"fr")])] } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return objectsArray.count } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows return objectsArray[section].sectionObjects.count } //нажатие на ячейку override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) if cell!.accessoryType == .None { cell!.accessoryType = .Checkmark self.allExersiseTable[indexPath.row] = true } else { cell!.accessoryType = .None self.allExersiseTable[indexPath.row] = false } //убираем эфект нажатой ячейки tableView.deselectRowAtIndexPath(indexPath, animated: true) } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) //отображаем элементы ячеек cell.textLabel?.text = objectsArray[indexPath.section].sectionObjects[indexPath.row].name cell.imageView?.image = UIImage(named: objectsArray[indexPath.section].sectionObjects[indexPath.row].image) //для предотвращения дублирования чекмаркеров в таблице по нажатию cell.accessoryType = allExersiseTable[indexPath.row] ? .Checkmark : .None //цвет чекмаркера cell.tintColor = UIColor.redColor() return cell } override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?{ return objectsArray[section].sectionName } } 
  • What is a checkmarker? - Max Mikheyenko
  • I have your code worked fine. somewhere else apparently a problem - Max Mikheyenko

1 answer 1

You need to store all the cells in an array. Create a separate class for the cell, and inside that class, catch the clicks. Then in the cell, declare the protocol of which you will call the delegate of your cell. When creating cells, declare them a delegate table. Then, when you click in a cell, you can pass it to the delegate method yourself. then by calling the indexPathForCell table: you recognize the index of the pressed cell, and then by simple sorting you can choose which of the cells you need to update and which ones you don’t. Perhaps not the most concise solution, but it definitely will help. Hope explained is available