繁体   English   中英

ios 8.1:类型“ViewController”不符合协议“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.

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