以下代码说明了我的类“MainVC”无法从UICollectionViewFlowLayout继承的错误,sizeForItemAt也没有自动完成,我错过了什么?我需要创建一个大小为屏幕宽度一半的单元格
extension HomeVC:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewFlowLayout {
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int { return subjectList.count }
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "subject", for: indexPath) as! SubjectCell
let subject = subjectList[indexPath.row]as Subjects
cell.subject = subject
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
return CGSize(width: UIScreen.main.bounds.width/2, height: 100.0)
}
}
答案 0 :(得分:1)
符合UICollectionViewDelegateFlowLayout
而不是UICollectionViewFlowLayout