首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译器说我不符合UICollectionViewDelegate;与实际使用相冲突

编译器说我不符合UICollectionViewDelegate;与实际使用相冲突
EN

Stack Overflow用户
提问于 2014-11-07 06:10:48
回答 1查看 42关注 0票数 1

我相信我遵循的是UICollectionViewDataSource,但编译器却不这么说。

我遗漏了什么?

代码语言:javascript
复制
import Foundation
import UIKit

class InviteFriendsViewController:UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

    @IBOutlet weak var collectionView: UICollectionView!

    @IBAction func navButtonAction(sender: UIBarButtonItem) {

    }

    @IBAction func segmentedControlAction(sender: UISegmentedControl) {
    }

    // -----------------------------------------------------------------------------------------------------
// MARK: UICollectionViewDataSource

    func collectionView(collectionView: UICollectionView, section: Int) -> Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView, indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell: AnyObject = collectionView.dequeueReusableCellWithReuseIdentifier("InviteFriendsVC", forIndexPath:indexPath)
        return cell as UICollectionViewCell
    }
}

我有两个功能,涵盖了所需的API.但是我得到了这个编译器错误。

为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-07 06:16:52

你必须以这样的方式声明你的函数:

代码语言:javascript
复制
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{

    return 1
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{

    let cell: AnyObject = collectionView.dequeueReusableCellWithReuseIdentifier("InviteFriendsVC", forIndexPath:indexPath)
    return cell as UICollectionViewCell
}

试试这个也许能帮到你。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26795170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档