UICollectionView Inside of UItableViewCell no horizontal scrolling

Viewed 358

i'm having this issue using Xcode 12.2 were i can't scroll in horizontal direction a UICollectionView, i have try multiples answers from the forum and none of then work for me

the exact behaviour is: the information charge fine in each UItableViewCell and part of the collection remains hidden on the right because is not scrollable.

while scrolling the UITableViewCells works fine you can scroll down and up, and cells information charge , but the UICollectionViews inside each UITableViewCells are not scrollable horizontally, and the information charge fine

first of all what i'm only trying to achieve is the scroll horizontally.

Heres my UITableView declaration on the View:

let tableSeasons: UITableView = {
        let table = UITableView(frame: CGRect.zero)
        table.register(NumberOfSeasonsCell.self, forCellReuseIdentifier: "seasonsRegister")
        table.backgroundColor = .clear
        table.layer.cornerRadius = 0
        table.separatorColor = .clear
        table.translatesAutoresizingMaskIntoConstraints = false
        table.showsHorizontalScrollIndicator = false
        table.showsVerticalScrollIndicator = false
        return table
    }()

here's the Delegate and DataSource protocols in VC:

extension SelectedShowVC: UITableViewDelegate, UITableViewDataSource {
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return arrayOfSeasonsInt.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        guard let cell = tableView.dequeueReusableCell(withIdentifier: "seasonsRegister", for: indexPath) as? NumberOfSeasonsCell else {
            return UITableViewCell()
        }
        cell.backgroundColor = .clear
        
        cell.selectionStyle = .none
        cell.seasonsCollectionView.delegate = self //here's the delegate and dataSource for the CollectionView
        cell.seasonsCollectionView.dataSource = self

        

        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 200
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
    
}

This is the code for UICollectionView declaration on the NumberOfSeasonsCell or UITableViewCell

lazy var seasonsCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.minimumLineSpacing = 15
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.backgroundColor = UIColor.clear
        cv.register(SeasonCell.self, forCellWithReuseIdentifier: "identifierSeasons")
        cv.showsHorizontalScrollIndicator = false
        cv.translatesAutoresizingMaskIntoConstraints = false
        return cv
    }()

Protocols for the UICollectionView

extension NumberOfSeasonsCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
            return arraySeasonsEpisodes.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifierSeasons", for: indexPath) as! SeasonCell
            cell.backgroundColor = .clear
            cell.model = arraySeasonsEpisodes[indexPath.item] //passing data for the DidSet
            return cell
}
    
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
            return CGSize(width: 150, height: 100)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
            return 15
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            print(indexPath.row)
    }
 
}

i've read that i should store the last position of the Table for scrolling the UICollectionView but i've tried but not work for me

0 Answers
Related