swift collection view deselects item when scroll off screen

The solution for “swift collection view deselects item when scroll off screen” can be found here. The following code will assist you in solving the problem.

class MyViewController {

var selectedIndexes = [IndexPath]()

func cellForItem(indexPath) {
cell.isSelected = selectedIndexes.contains(indexPath)
}

func didSelectCell(indexPath) {
if selectedIndexes.contains(indexPath) {
selectedIndexes.remove(indexPath)
} else if selectedIndexes.count < limiit { selectedIndexes.append(indexPath) } } }

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in