Hi, im struggle with my cell model it's only showing my array position 0
what i'm trying to reach is show in each UICollectionView the information inside
arregloBidimencional
which contains let episodes: [episodess]? and let tack: Int?
episodess is my main struct for the didSet inside each UICollectionviewCell
and tack is my identifier for each array of [episodess]
var arraySeasonsEpisodes: [episodess] = [] its type of episodess
so my model to get the previous data is
so the didset in UICollectionViewCell it's set like this
this is how i storage the data from the json dictionary
what i'm trying to reach is show in each UICollectionView the information inside
arregloBidimencional
which contains let episodes: [episodess]? and let tack: Int?
episodess is my main struct for the didSet inside each UICollectionviewCell
and tack is my identifier for each array of [episodess]
Code Block func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if collectionView == UI.castCollectionView{ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifierSeasons", for: indexPath) as! SeasonCell cell.backgroundColor = .clear let arreglo = arraySeasonsEpisodes[indexPath.item] cell.model = arreglo return cell }
var arraySeasonsEpisodes: [episodess] = [] its type of episodess
so my model to get the previous data is
Code Block struct episodess: Initiable { let episode_number: Int? let name: String? let still_path: String? init() { self.episode_number = 0 self.name = "" self.still_path = "" } init(dictionary: NSDictionary) { self.episode_number = dictionary["episode_number"] as? Int ?? 0 self.name = dictionary["name"] as? String ?? "" self.still_path = dictionary["still_path"] as? String ?? "" } } struct arregloBidimencional: Initiable { let episodes: [episodess]? let tack: Int? init() { self.episodes = [episodess]() self.tack = 0 } init(arreglo: [episodess], tag: Int) { self.episodes = arreglo self.tack = tag } }
so the didset in UICollectionViewCell it's set like this
Code Block class SeasonCell: UICollectionViewCell { var model: episodess? { didSet { guard let viewModel = model else { return } let episodio = viewModel.episode_number let nombre = viewModel.name let guardado = viewModel.still_path episodeNumber.text = "Episode Number: \(episodio ?? 0)" episodeName.text = "Episode Name: \(nombre ?? "")" let image = "https://image.tmdb.org/t/p/w500\(guardado ?? "")" if image == "" || image == "undefined" { seasonImage.image = UIImage(named: "") seasonImage.contentMode = .scaleAspectFill }else{ seasonImage.downloaded(from: image) seasonImage.contentMode = .scaleAspectFill } } }
this is how i storage the data from the json dictionary
Code Block let toneCategories = jsonDictionary["episodes"] as? [NSDictionary] ?? [] for category in toneCategories { let show = episodess(dictionary: category) arraySeasonsEpisodes.append(show) let number = Int(season_number) ?? 0 let reversedCollection = (1 ... number) //for index in reversedCollection { for (index, element) in reversedCollection.enumerated() { print(index, ":", element) let fixed = index - 1 if fixed <= 0 { let arreglo = arregloBidimencional(arreglo: [show], tag: 0) arregloDeArreglos.append([arreglo]) }else if fixed >= 1{ let fixed2 = index let arreglo = arregloBidimencional(arreglo: [show], tag: fixed2) arregloDeArreglos.append([arreglo]) } } }
If the collectionViews are inside tableView cells, when you dequeue a cell, you need to define the content of the cell in the cellAtRow func. Otherwise, you get reusing queued cells, with any content that is left there.
The content should be the corresponding collectionView.
The content should be the corresponding collectionView.