ios 8.1:类型“ViewController"不符合协议“UICollectionViewDataSource" [英] ios 8.1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'
问题描述
我在编译 swift 应用程序 (iOS 8.1) 时遇到以下错误
I'm getting the following error when compile swift application (iOS 8.1)
类型 'ViewController' 不符合协议 'UICollectionViewDataSource'
Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'
在class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate"处线
at "class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate" line
我刚刚在这里查看了几篇帖子,但没有人帮我解决这个问题.
I've just checked few posts here but no one helps me to solve this problem.
这是 ViewController.swift 文件的代码:
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.
Check for typos in your code, Like - use "numberOfItemsInSection"instead numberOfItemInSection.
这篇关于ios 8.1:类型“ViewController"不符合协议“UICollectionViewDataSource"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!