ios 8.1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 04:12:27

问题


I'm getting the following error when compile swift application (iOS 8.1)

Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'

at "class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate" line

I've just checked few posts here but no one helps me to solve this problem.

Here's the code of ViewController.swift file:

import UIKit

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var tableDescription: [String] = []
var tableNumbers: [String] = []

override func viewDidLoad() {
    super.viewDidLoad()
    self.populateView()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func collectionView(collectionView: UICollectionView, numberOfItemInSection section: Int) -> Int{
    return tableDescription.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
    let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as CollViewCell

    cell.lblDescription.text = tableDescription[indexPath.row]
    cell.lblNumber.text = tableNumbers[indexPath.row]

    return cell
}

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    println("Cell \(indexPath.row) selected")
}
 }

Thank you so much helping me.


回答1:


Check for typos in your code, Like - use "numberOfItemsInSection"instead numberOfItemInSection.



来源:https://stackoverflow.com/questions/29049045/ios-8-1-type-viewcontroller-does-not-conform-to-protocol-uicollectionviewdat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!