ios 8.1:类型'ViewController'不符合协议'UICollectionViewDataSource'

时间:2015-03-14 12:40:09

标签: ios swift uiviewcontroller viewcontroller

编译swift应用程序时,我收到以下错误(iOS 8.1)

  

键入' ViewController'不符合协议' UICollectionViewDataSource'

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

我刚刚在这里查了几篇帖子,但没有人帮我解决这个问题。

这里是ViewController.swift文件的代码:

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")
}
 }

非常感谢你帮助我。

1 个答案:

答案 0 :(得分:2)

检查代码中的拼写错误,比如 - 使用“numberOfItemsInSection”而不是numberOfItemInSection。