ios 8.1:类型“ViewController"不符合协议“UICollectionViewDataSource" [英] ios 8.1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'

查看:31
本文介绍了ios 8.1:类型“ViewController"不符合协议“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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆