简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM