ios - 在 swift 4 中取消选择 Collectionview 中的复选标记

标签 ios swift checkbox uicollectionview

我在主视图 Controller 中显示带有多个复选标记的搭配 View 。它工作正常

enter image description here

选择复选标记后,数据显示到下一个 View Controller 中。 它也正在发挥作用。当我回到主视图 Controller 时,我选择的复选标记并未取消选中。如何取消选中选定的复选标记。

我使用了这个引用 https://github.com/maximbilan/CheckMarkView

@IBOutlet weak var checkMarkViews: CheckMarkView!


    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {


        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)as! CustomCollectionViewCell

        let row = indexPath.row

        cell.CoutnryImages.downloadImageFrom(link: imagesarray[row] , contentMode: .scaleToFill)

        cell.countrynmae.text = itemsarray[row]

        cell.checkMarkViews.setNeedsDisplay()

      return cell

    }


    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        let cell = CollectionView.cellForItem(at: indexPath) as! CustomCollectionViewCell

        var indexpathvalues = indexPath.row   

        cell.checkMarkViews.checked = !cell.checkMarkViews.checked

        if cell.checkMarkViews.checked == true
        {

           PassedID.append(idarray[indexpathvalues])
            _selectedcell.add(indexpathvalues)

        }
        else
        {
        if PassedID.isEmpty
            {
                print("no Item found ")
            }
            else
            {
                 _selectedcell.remove(indexpathvalues)
                PassedID.removeLast()
            }

        }

    }

    @IBAction func Addbutton(_ sender: UIBarButtonItem) {

              performSegue(withIdentifier: "next", sender: self)

    }

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let vc = segue.destination as? nextViewController

        vc?.arrayvalues = self.PassedID

        _ = navigationController?.popViewController(animated: true)       

    }

how to uncheck the multiple selection after back to main view controller  

最佳答案

override func viewWillAppear(_ animated: Bool) {

    // get visible cells and un check them

    let visibleCell = cc.visibleCells as! [CustomCollectionViewCell]

    for cell in visibleCell
    {
        // un check here

    }

}

关于ios - 在 swift 4 中取消选择 Collectionview 中的复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49495022/

相关文章:

UILabel 上的 iOS 渐变效果

ios - 移动到后台后保持调度队列运行 5 秒

ios - 在 Xcode 6 beta 中使用 Images.xcassets

android - 在一个 Activity 中显示多个 ImageView

javascript - jquery:检测属于某个类的任何元素的变化

ios - 获取对象 NSDictionary 的键

ios - 为 XCTest 模拟较低的操作系统版本

ios - 当元素添加/删除到数组时得到通知

ios - 为什么 ViewController 类不需要遵守 NSObject 协议(protocol),而其他类需要遵守

javascript - 除了 Angular-Material md-checkboxes 之外,默认的浏览器复选框也出现了