我在主视图 Controller 中显示带有多个复选标记的搭配 View 。它工作正常
选择复选标记后,数据显示到下一个 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/