【问题标题】:ios 8.1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'ios 8.1:类型“ViewController”不符合协议“UICollectionViewDataSource”
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 2014-11-08
    相关资源
    最近更新 更多