имеем на странице два UICollectionView например
var selectedIndex = Int ()
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCollectionViewCell
if(collectionView == self.collectionView) {
cell.name_category.text = heroes[indexPath.row].category_name
if selectedIndex == indexPath.row
{
cell.backgroundColor = UIColor.green
}
else
{
cell.backgroundColor = UIColor.red
}
}
if(collectionView == self.collectionViewData) {
cell.name_news.text = heroes[indexPath.row].name
cell.text_news.text = heroes[indexPath.row].desc
}
return cell;
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// return print(indexPath.row)
selectedIndex = indexPath.row
// self.collectionView.reloadData()
}
но не могу решить проблему с выделением ячейки в конкретной коллекции. Если выделить одну ячейку в одной коллекции то она будет и на другой отражатся