mardi 18 février 2020

Checkbox not working separately in swift. How can I make it separate?

I have problem about checkbox in swift. I use M13Checkbox, found in github. In my app when I click at index 0 cell's checkbox, all even numbers(index) cells checkboxs checked. And also when I click at index 1 cell's checkbox all odd numbers(index) cell's checkboxs get checked. I can't find any reason for that Can anybody help me?

Here my code:

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


    var searched: String?
    if isSearching {
        searched = filteredArray[indexPath.row]
    }else{
        searched = self.orderId[indexPath.row]
    }


    cell.orderIdLabel.text = searched

    //cell.orderIdLabel.text = self.orderId[indexPath.row]
    cell.detailLabel.text =  self.newDatas[indexPath.row]
    cell.alindiLabel.text = "Alındı: "
    cell.temizlemedeLabel.text = "Temizlemede: "
    cell.teslimEdildiLabel.text = "Teslim edildi: "
    cell.kapidaOdemeLabel.text = "Kapıdan alınacak tutar: \(self.ucret[indexPath.row])"

    cell.deleteButton.tag = indexPath.row
    cell.urunEklemeButton.tag = indexPath.row

    cell.uncheckedButtonAlindi.tag = indexPath.row
    cell.uncheckedButtonTemizleme.tag = indexPath.row
    cell.uncheckedButtonTeslim.tag = indexPath.row


    return cell

}

Here my checkbox function:

@objc func checkControlAlindi(sender : M13Checkbox?) {

    switch sender!.checkState {
        case .checked:
            let indexPath = IndexPath(row: (sender!.tag), section: 0)
            let cell = tableView.cellForRow(at: indexPath) as! sipCell
            print(cell.orderIdLabel.text!)
            print("alındı kısmına bastınız... ", (sender!.tag))

        break

        case .unchecked:
             print("unchecked")

        break

        case .mixed:
            //empty...
        break
    }





}

And here my checkbox:

let uncheckedButtonAlindi: M13Checkbox = {
    let button = M13Checkbox()
    button.tintColor = .orange
    button.boxType = .circle

    button.secondaryTintColor = .lightGray
    button.boxLineWidth = 4
    button.checkmarkLineWidth = 3
    button.addTarget(self, action: #selector(ViewController.checkControlAlindi(sender:)), for: UIControl.Event.valueChanged)
    return button
}()



Aucun commentaire:

Enregistrer un commentaire