Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'

I am following a tutorial where using the UIPickerController to operate the camera. However when implementing UICollectionViewDatsaSource, I get an error saying that ViewController does not conform to the UICollectionViewDataSource protocol.

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIImagePickerControllerDelegate, UINavigationControllerDelegate 

Any idea on how to fix this problem?

like image 635
RPMouton Avatar asked Sep 26 '14 16:09

RPMouton


2 Answers

You must implement this two method in your ViewController class:

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {}

P.S. - Your function prototype should exactly match with above functions.(remove any '!' if present)

like image 106
Aks Avatar answered Nov 08 '22 23:11

Aks


You have to implement these two method in your ViewController class for Collection View :

 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    <#code#>
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    <#code#>
}
like image 3
Hemant Gupta Avatar answered Nov 08 '22 23:11

Hemant Gupta