API, который возвращает необязательную ячейку.

ние ячейки TableView CheckMark, удаленное после прокрутки вверх, исправит TableView. У вас много раз возникали проблемы с установкой галочки после прокрутки вверх, затем прокрутки вниз. Чтобы показать, что ячейка вашей галочки будет удалена, потому что ячейка dequeueReusableCell Ваш код и решил вашу проблему.

Любая дополнительная помощь, так что отправьте массаж. Большое спасибо. :)

class ViewController: UIViewController , UITableViewDataSource , UITableViewDelegate{

var temp = [Int]()
var numarr = [Int]()

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "id")
    cell = UITableViewCell.init(style: .default, reuseIdentifier: "id")
    cell?.textLabel?.text = String(numarr[indexPath.row])
    if temp.contains(numarr[indexPath.row] as Int)
    {
        cell?.accessoryType = .checkmark
    }
    else
    {
        cell?.accessoryType = .none
    }
    return cell!
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let cell = tableView.cellForRow(at: indexPath)
    if temp.contains(numarr[indexPath.row] as Int)
    {
        cell?.accessoryType = .none
        temp.remove(at: temp.index(of: numarr[indexPath.row])!)
    }
    else
    {
        cell?.accessoryType = .checkmark
        temp.append(self.numarr[indexPath.row] as Int)
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    for i in 1...100
    {
        numarr.append(i)
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

Ответы на вопрос(2)

Ваш ответ на вопрос