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
Make sure you have the correct reuse identifier set for the cell.
I had collectionViewCell blank problems until i realized my viewController was not in file i did not know how this file was end up trash it took me while to figure it out.
Problem is with setting the title to button, use the following code.
override func
collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! UICollectionViewCell
var button = cell.viewWithTag(1) as! UIButton
//button.titleLabel?.text = Array[indexPath.row]
button.setTitle(Array[indexPath.row], forState: UIControlState.Normal)
return cell
}
Hope it helps
check that you are setting CollectionView outlets (datasource , delegate) in your storyBoard as show below
Select the UIButton
in storyboard, check the installed
as the bottom left in the image below.
Check to make sure that the cell is not hidden. Add this code below
cell.isHidden = false