【发布时间】:2019-12-17 05:46:29
【问题描述】:
我在UITableViewCell 中有UICollectionView,它的委托和数据源在表格单元格类中声明。它在第一次加载时工作正常,但后来在我滚动收藏时改变了它的大小。
我注意到sizeForItemAt 仅在加载时调用,而不是在滚动期间设置单元格时调用。
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)
}
}
【问题讨论】:
-
发布您已经尝试过的代码。
-
你还没有调用 setCollection() 请在 viewDidload() 中调用
标签: ios swift uitableview uicollectionview