我相信我跟随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 ......但是我得到了这个编译错误。
为什么呢?
答案 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
}
试试这可能对你有帮助。