I am having UICollectionView
inside a UITableViewCell
and its delegate and datasource are declared there in table cell class. It works fine for first time loading but later on changes it's size when I scroll collection.
I noticed sizeForItemAt
is called only while loading but not while setting the cells during scroll.
class HomeCell: UITableViewCell {
@IBOutlet weak var collHomeSongs: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func setCollection() {
collHomeSongs.delegate = self
collHomeSongs.dataSource = self
}
}
extension HomeCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize.init(width: 120, height: 180)
}
}