Collection View Cells not appearing

前端 未结 14 835
迷失自我
迷失自我 2021-02-07 08:40

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

14条回答
  •  一向
    一向 (楼主)
    2021-02-07 09:33

    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

提交回复
热议问题