1

Clase Controller

var items = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"]


        // MARK: - UICollectionViewDataSource protocol

        // tell the collection view how many cells to make
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return self.items.count
        }

        // make a cell for each cell index path
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {



            // get a reference to our storyboard cell
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellCollectionViewCell", for: indexPath as IndexPath) as! CellCollectionViewCell

            // Use the outlet in our custom class to get a reference to the UILabel in the cell
            cell.myLabel.text = self.items[indexPath.item]
            cell.backgroundColor = UIColor.cyan // make cell more visible in our example project

            return cell
        }

        // MARK: - UICollectionViewDelegate protocol

        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            // handle tap events
            print("You selected cell #\(indexPath.item)!")
        }

Luego tengo esta clase con esta configuracion

introducir la descripción de la imagen aquí

donde dice Identifier le escribi "CellCollectionViewCell"

Tengo separado en clases introducir la descripción de la imagen aquí

Al llegar a la linea de

 // get a reference to our storyboard cell
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellCollectionViewCell", for: indexPath as IndexPath) as! CellCollectionViewCell

se cae , alguna ayuda con esto ? me parece que deberia ser sencillo , aunque no logro hacer que funcione , en el viewDidLoad tengo

  override func viewDidLoad() {
    super.viewDidLoad()
    setupLabels()
    setupStyles()
    carosuel.delegate = self
    carosuel.dataSource = self 
}

1 respuesta 1

1

Encontre mi problema , En el viewDidLoad metodo me faltaba 1 linea

     override func viewDidLoad() {
        super.viewDidLoad()
        setupLabels()
        setupStyles()

// ESTA LINEA QUE REGISTRA
         self.carosuel.register(UINib(nibName:"CellCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: reuseIdentifier)

        carosuel.delegate = self
        carosuel.dataSource = self
    }

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.