Answer the question
In order to leave comments, you need to log in
CollectionView how to create/edit cells in storyboard?
Good day! I'm trying to develop on iOS, I got stuck on one of the main design elements - collectionView, created the collectionView itself in the storyboard, several cells, edited them the way I needed, added images to them, and everything would be fine, but after launching the application, the cells do not are displayed. Having searched for a problem on the Internet, I did not find the answer I needed, everyone writes about how to create / edit cells programmatically. Actually, the question itself is, is it possible to create and fill cells without code, just in a storyboard?
Answer the question
In order to leave comments, you need to log in
It's impossible to fix the problem without seeing your code, but I can guess what the problem might be.
You may have set up cells in the storyboard, but at the same time, you need to tell the collection which cells to load.
That is, you arrange the elements in the storyboard as you need, and be sure to assign an identifier to the cell, for example "item", and, preferably, specify a custom class.
After that, you have a method in your CollectionViewController
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier "item", for: IndexPath) as! CustomCell
// теперь cell у нас нужная нам ячейка, настройки IBOutlets и IBActions у нас в ее кастомном классе, если
необходимо можем тут настроить какую нибудь логику. После настройки логики, нам нужно вернуть из
метода эту ячейку
return cell
}
Is it even possible to create and fill cells without code, just in a storyboard?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question