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

时间:2014-11-07 06:10:48

标签: swift xcode6 uicollectionviewdelegate

我相信我跟随UICollectionViewDataSource,但编译器却说不然。
我错过了什么?

enter image description here

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
    }
}

enter image description here

我有两(2)个func,涵盖了所需的API ......但是我得到了这个编译错误。
为什么呢?

1 个答案:

答案 0 :(得分:2)

您必须以这种方式声明您的功能:

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
}

试试这可能对你有帮助。