我相信我遵循的是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
}
}

我有两个功能,涵盖了所需的API.但是我得到了这个编译器错误。
为什么?
发布于 2014-11-07 06:16:52
你必须以这样的方式声明你的函数:
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
}试试这个也许能帮到你。
https://stackoverflow.com/questions/26795170
复制相似问题