Reputation: 1744
I am trying to implement a Collection view that is wired to a collection view in the interface builder as an IBOutlet. As required, I am trying to declare the UIViewController class file that I have created for the controller that contains the Collection View as a UICollectionViewDataSource.
However, Xcode keeps giving me an error that the view controller doesn't conform to the protocol of UICollectionViewDataSource, despite it being declared right there.
I am setting the controller as the datasource and delegate like so:
ObjectsCollection.delegate = self
ObjectsCollection.dataSource = self
Here is s screenshot of the error:
What is the cause of the error? I can't seem to find it.
Upvotes: 1
Views: 2397
Reputation: 385998
The UICollectionViewDataSource
protocol defines two required methods:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
You are missing one or both of them.
Here's how you can see what you're missing:
Go to the menu bar and select View > Navigators > Show Issue Navigator (default shortcut: ⌘4).
In the Issue Navigator, click on the disclosure triangles to turn them down until the navigation shows you the missing required functions. Or, option-click on the top triangle until it opens all triangles in the tree.
Example:
Upvotes: 5
Reputation: 15464
The thing is if you declared your class will conform a protocol you have to implement required methods from that protocol.
Upvotes: 0