无法识别的选择器发送到集合视图方法numberOfItemsInSection中的实例

时间:2018-11-15 04:13:37

标签: ios swift uicollectionview

虽然我将UICollectionView DelegateDatasource添加的情节提要与Objective C相同,但是却出现以下错误-

collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fb74482b200'

1 个答案:

答案 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
    }