I have 2 collectionViews and trying to pass data to one viewcontroller the problem is the second collectionsView show me the indexPath of the firstCollectionView when didSelect is fired
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? DetailsViewController {
let collectionView = sender as! UICollectionView
let index = collectionView.indexPathsForSelectedItems?.first
let topSeller = topSellers[index!.row]
let topGame = topGames[index!.row]
if collectionView.tag == 0 {
destination.image = UIImage(named: topSeller.imageGame!)
destination.titleGame = topSeller.titleGame
destination.descriptionGame = topSeller.description!
destination.youtubeURL = topSeller.youtubeURL
destination.gameUrlBuy = topSeller.buyGameURL
}else if collectionView.tag == 1 {
destination.image = UIImage(named: topGame.imageGame!)
destination.titleGame = topGame.titleGame
destination.descriptionGame = topGame.description!
destination.youtubeURL = topGame.youtubeURL
destination.gameUrlBuy = topGame.buyGameURL
}
}
}
}
extension FirstTabViewController: UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView == firstCollection {
performSegue(withIdentifier: "Details", sender: collectionView)
}else if collectionView == secondCollection {
performSegue(withIdentifier: "Details", sender: collectionView)
}
}
}