Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a collection view with static cells only? [duplicate]

I want to add a vertical collection view that contains 7 static cells. I know how to do it dynamically, but i don't see a reason to do so.

Do i have to use the cellForRow method? I Added a collection view to my viewController, and added 4 cells, wired up the delegate from the collectionView to the vc (using storyBoard), but when i run it it shows me an empty collectionView.

I did set up the numberOfSections to return 1 and the numberOfCellsInSection to return 7. So did i miss anything? or do i have to conform to DataSource protocol and implement the cellForRow method ? (in TableView i can skip the cellForRow when using static cells).

Thanks for the help.

like image 480
Yevgeni Avatar asked Dec 11 '22 05:12

Yevgeni


1 Answers

From the official document:

Every collection view must have a data source object. The data source object is the content that your app displays. It could be an object from your app’s data model, or it could be the view controller that manages the collection view. The only requirement of the data source is that it must be able to provide information that the collection view needs, such as how many items there are and which views to use when displaying those items.

like image 109
Timuçin Avatar answered Jan 26 '23 00:01

Timuçin