![](/img/trans.png)
[英]Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'
[英]ios 8.1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'
編譯 swift 應用程序(iOS 8.1)時出現以下錯誤
類型“ViewController”不符合協議“UICollectionViewDataSource”
在“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")
}
}
檢查代碼中的拼寫錯誤,例如 - 使用“numberOfItemsInSection”而不是 numberOfItemInSection。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.