虽然我将UICollectionView
Delegate
和Datasource
添加的情节提要与Objective C
相同,但是却出现以下错误-
collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fb74482b200'
答案 0 :(得分:0)
您已经添加了课程-
class YourViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource
实施以下方法-
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "yourCell", for: indexPath as IndexPath)
return cell //return your cell
}