1

我相信我正在关注 UICollectionViewDataSource,但编译器另有说明。
我错过了什么?

在此处输入图像描述

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

在此处输入图像描述

我有两 (2) 个 func 涵盖了所需的 API……但我收到了这个编译器错误。
为什么?

4

1 回答 1

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
}

试试这个可能对你有帮助。

于 2014-11-07T06:16:52.593 回答