1

I believe I'm following the UICollectionViewDataSource, but the compiler says otherwise.
What am I missing?

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

I have two (2) func that covers the required APIs... but I'm getting this compiler error.
Why?

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105

1 Answers1

2

You have to declare your functions like this way:

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
}

Try this may be it can help you.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165