I was building an iOS app for my hospital using collection view. However, I need to use multiple sections for the specialist clinic depends on the purpose. I already complet
If you have different cells layout requirement in that case you should use different custom cells with different reuse identifier. As I can see in your code you have same layout of cell with different datasource.
So I would say try to subclass the collectionview cell and put a IBOutlet property for button through xib or storyboard in the subclass.
You can refer this question: how to create custom UICollectionViewCell
Make sure assigning DataSource & Delegate to CollectionView
1.Give number of sections you wanna show using below method
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
2.Set item count of each sections for CollectionView using below method.
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (section == 0) ? list.count : list2.count
}
3.Assigning cell for each item to CollectionView.
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//If you are using multiple cells based on section make condition
if indexPath.section == 0 {
//make sure the identifier of your cell for first section
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath)
// do your stuffs
return cell
}else{
//make sure the identifier of your cell for second section
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath)
// do your stuffs
return cell
}
}