Hello fellow overflowers so I set up a collectionView and configure it but when I run the simulator I get a lot of cells just mixed with each other like in the first picture.
I have added the identifier at the storyboards cell also created the class for the cell but I can’t seem to know what the problem might be since it never happened.
How I want my cell to be I will show on the second picture.
the code:
extension dashboardViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
return 15
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "dashboardCollectionViewCell", for: indexPath) as? dashboardCollectionViewCell else {return UICollectionViewCell()}
return cell
}
}
2
Answers
Seems that your collection view cell’s size has not correct set.
If your are using
UICollectionViewFlowLayout
, maybe you can check the layout object’sitemSize
property.By the image provided, it seems you haven’t set the item size of the cell
in horizontal layout as well as the minimum spacing between each cell. You can do that (set item size) by calling
this method from
UICollectionViewDelegateFlowLayout
.You can also do this using storyboard.
Size Inspector