Problem with Code of prepareforsegue - UiCollectionView

Hello!
I have a problem to make a prepareforsegue into UIcollectionview /CoreData.
I need that the “cell” in View FilmList with tap go to open View of Film Detail.
I use it for tableview and I don’t have a problem but with Uicollectonview, I have any problems.

I hope you can help me :slight_smile:
This is the code
VIEW FILMLIST

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

        // controlliamo che il nome del segue corrisponda alla parola dettaglio
        if segue.identifier == "VediScheda" {

            // controlliamo quale cella è stata toccata
            if let indexPath = self.collectionView.indexPathsForSelectedItems {


                // estraiamo dal segue il DetailController
                let controller = segue.destination as! SchedaAnime

                let cell = sender as! UICollectionViewCell

                
                let indexPath = self.collectionView!.indexPath(for: cell)
        

                let selectedData = taskArray[(indexPath?.row)!]

                // taskarrayscheda is the variable that will be sent   
         
		    controller.taskArrayScheda = selectedData

               
            }
        }
    }

VIEW DETAILS

import UIKit
import CoreData


// Global Variables and Constants
let appDelegateScheda = UIApplication.shared.delegate as? AppDelegate

class SchedaAnime: UIViewController, UITextFieldDelegate {
    
    
    // Varables
var taskArrayScheda : NewAnime?


 override func viewDidLoad() {
        super.viewDidLoad()
        
       
        
        if(self.taskArrayScheda != nil) {
        
            let schedaOk = taskArrayScheda
            
            titoloScheda.text = taskArrayScheda?.titolo
            
           
            
        } else { print("error array vuoto") }

}

Hi,

Not sure I am 100% right but you are declaring two variables with the same name

if let indexPath = self.collectionView.indexPathsForSelectedItems {

and again inside this block

let indexPath = self.collectionView!.indexPath(for: cell)

I would imagine this is causing a conflict at runtime.

Let me know how you get on.

Thanks

James

1 Like

thank you so much
I have correct the problem… :slight_smile:

No problem, hope it worked

1 Like

@jamesbuck thank you for helping out @pegaso101!

Best,
Gina

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.