A
A
artursk2015-12-11 15:39:27
iOS
artursk, 2015-12-11 15:39:27

How to prevent duplicate checkmarker in UITableView?

Guys help pliz, who has five minutes... Created a table of three sections, added a checkmarker. I can not remove the checkmarker duplication in the table on the following cells from the clicked ones. I did everything according to the course on the SwiftBook resource. Thanks
import UIKit
class AllExersiseTableViewController: UITableViewController {
//create sections
struct Objects {
var sectionName: String!
var sectionObjects: [(name: String, image:String)]!
}
var objectsArray = [Objects]()
//create an array with cells to prevent duplicate checkmarkers in the table on click
var allExersiseTable = [Bool](count: 15, repeatedValue: false)
override func viewDidLoad() {
super.viewDidLoad()
objectsArray = [Objects(sectionName: "Standing", sectionObjects: [(name: "Squats", image:"bb"), (name: "Pushups", image:"bt"), (name: "Pullups", image:"ca"), (name: "Jumping", image:"co"), (name: "Running", image:"de")]), Objects(sectionName: "Sitting", sectionObjects : [(name: "RUN", image:"en"), (name: "JUMP", image:"al"), (name: "SQUAT", image:"au"), (name: "PUSH" , image:"es"), (name: "PUSH", image:"fr")]), Objects(sectionName: "Special", sectionObjects: [(name: "RUN", image:"en"), ( name: "JUMPS", image:"al"), (name: "SQUAT", image:"au"), (name: "PUSH", image:"es"), (name: "PUSH", 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
}
//Click on cell
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
}
// remove cell pressed effect
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
//display cell elements
cell.textLabel?.text = objectsArray[indexPath.section].sectionObjects[indexPath.row].name
cell.imageView?.image = UIImage(named: objectsArray[indexPath.section].sectionObjects[indexPath.row].image)
/ /to prevent duplicate checkmarkers in the table on click
cell.accessoryType = allExersiseTable[indexPath.row] ? .Checkmark : .None
//checkmark color
cell.tintColor = UIColor.redColor()
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
return objectsArray[section].sectionName
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question