【发布时间】:2015-03-14 12:40:08
【问题描述】:
编译 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")
}
}
【问题讨论】:
-
您使用的是哪个 Xcode 版本?你在最新的 Xcode 中得到了这个吗?
标签: ios swift uiviewcontroller viewcontroller