Checklist Data Trouble

I am trying to make a checklist. I made a tableview. Have an array with 600 items, listed each one on its own line. I got it to make a checkmark, and remove it. But if I check the first item, it also checks every 16th item throughout the list. Im lost.HELP!
Thank You In Advance,
Joe

Welcome to the community Joe!

What does your code look like???

Thank you for trying to help Mikaela. I’m totally new to this, and clueless. Anywhere you check, it automatically checks every sixteenth name, to the end of the list. Frustrating.
Thanks again.
JoeGraves

// ViewController.swift

// T206B

//

// Created by Joe Graves on 5/24/20.

// Copyright © 2020 Joe Graves. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

@IBOutlet var tableView: UITableView!

let names = [

“Abbaticcho, Ed (Blue Sleeves)”,

“Abbaticchio, Ed (Brown Sleeves)”,

“Abbott, Fred”,
]

override func viewDidLoad() {
    super.viewDidLoad()
    
    tableView.delegate = self
    tableView.dataSource = self
    let header = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 100))
    
    let label = UILabel(frame: header.bounds)
    label.text = "T206 CHECKLIST"
    label.textAlignment = .center
    header.addSubview(label)
    tableView.tableHeaderView = header
}

}

extension ViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCell.AccessoryType.none {
        tableView.cellForRow(at: indexPath)?.accessoryType =
            UITableViewCell.AccessoryType.checkmark
    
    
    }

}
}

extension ViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return names.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

    cell.textLabel?.text = names[indexPath.row]
    
return cell
}

}

I believe this is happening because you are dequeuing your cells.

I’m guessing if you count it, when you first load the VC your screen holds about 16 rows.

So after clicking one when that cell is reused and dequeued again it still had the check mark there.

You need to have another proper with your names array to change the value to “checked” or something, and then in your didSelectRowAt function you’re evaluating that property and then assigning the check mark or not.

NOT having it depend on if the cell has been checked or not