I want to display as many collectionViewCells
with buttons
as there are strings in my array. but when I start the simulator there is just the backgroun
func layoutCells() {
let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 10, right: 10)
layout.minimumInteritemSpacing = 5.0
layout.minimumLineSpacing = 5.0
layout.itemSize = CGSize(width: (UIScreen.mainScreen().bounds.size.width - 40)/3, height: ((UIScreen.mainScreen().bounds.size.width - 40)/3))
collectionView!.collectionViewLayout = layout
}
Try this. Call this function from view did load. I think the problem is that your collection is not laid out correctly.
func viewDidLoad() {
layoutCells()
}
If this works you can modify the layout options to meet your needs.
I had a similar problem, I found this that was somehow restraining the size of my cell. Hope this helps.
Ideas:
print
statements inside your cellForItemAtIndexPath
function to see if it's being called ever.Array
is actually a type in Swift. Using that as your variable name might be messing with the logic somehow. Rename it to array
(lowercase). I believe this is best practice for variable names anyway.cellForItemAtIndexPath
, such as changing the background color. If that works, maybe there's just something wrong with what you're doing with tags.First of all check you have used this method:-
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return searches.count
}
There’s one search per section, so the number of sections is the count of the searches array. so also we can use as per needed this method.by default we can use retuen 1
And Follow step in the Link for better soluation Check this link
Did you set the CollectionViewController
to the storyboard identity inspector? :)
And I would try to call the reloadData()
after you change the data in the viewDidLoad
method.
Hope that helps
Your problem is in
func collectionView(collectionView: UICollectionView, numberOfItemsSection section: Int)
method signature. It is wrong. It should be
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
and with override
specification (because UICollectionViewController
has own, this why you get empty collection).
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return Array.count
}