mardi 28 août 2018

Checkbox tick is not getting deselect when i come back to same screen

I have one table view to select the items needs to pass to cart page by using checkbox. Now when i select any date i.e when i select any 3 items and i move that date to cart page.And when i come back first items check box only getting removed. 2nd,3rd item check box image is still as tick mark is there. But its not selected, only image is showing. I tried all way in view will disapperar , viewwill appear But still only first items of table view check box is getting remove 2nd, 3rd items check box is still having checkbox.How can i solve that ?

@IBAction func checkBoxClicked(_ sender: Any) {
        guard let button = sender as? UIButton else {
            return
        }

        self.putCheckBox(tag: button.tag)
    }

func putCheckBox(tag: Int){
        let index = IndexPath(item: tag, section: 0)
        let cell = self.tableView.cellForRow(at: index) as! SubCatTableCell
        if let ct = self.subCatProducts?[index.row]{
            ct.customCheckBox = !ct.customCheckBox
            if ct.customCheckBox {
                cell.tickButnOutlet.setImage(#imageLiteral(resourceName: "checked"), for: .normal)
                ct.customCheckBox = true
                if ct.customCount == 0{
                    ct.customCount += 1
                    cell.noOfQtyLbl.text = "\(ct.customCount)"
                }
                let val = prefs.value(forKey: Constants.Keys.CategoryInCart) as? String
                if ct.categoryName != val{
                    if val != nil{
                        self.showAlertWithSingleButton(message: "Products addeed", okAction: {
                            if ct.customCheckBox{
                                cell.tickButnOutlet.setImage(#imageLiteral(resourceName: "checked"), for: .normal)
                            } else {
                                cell.tickButnOutlet.setImage(#imageLiteral(resourceName: "Unchecked"), for: .normal)
                            }
                            ct.customCheckBox = false
                            self.getSubCat()
                            self.collectionViewCellClicekd = true
                        }, cancelAction: {
                            if ct.customCheckBox{
                                cell.tickButnOutlet.setImage(#imageLiteral(resourceName: "checked"), for: .normal)
                            } else {
                                cell.tickButnOutlet.setImage(#imageLiteral(resourceName: "Unchecked"), for: .normal)
                            }
                            ct.customCheckBox = false
                            self.collectionViewCellClicekd = true
                            self.getSubCat()
                        })
                    }
                }

            }else{
                ct.customCount = 0
                cell.noOfQtyLbl.text = "\(ct.customCount)"
                cell.tickButnOutlet.setImage(#imageLiteral(resourceName: "Unchecked"), for: .normal)

            }
        }
    }

override func viewWillAppear(_ animated: Bool) {


        self.getSubCat() // api call for loading the date


    }

Please let me know how can i solve this issue !!

Thanks in advance !




Aucun commentaire:

Enregistrer un commentaire