Collection View Cells not appearing

前端 未结 14 826
迷失自我
迷失自我 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:31

    Make sure you have the correct reuse identifier set for the cell.

    0 讨论(0)
  • 2021-02-07 09:32

    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.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-07 09:33

    check that you are setting CollectionView outlets (datasource , delegate) in your storyBoard as show below

    helpful image link

    0 讨论(0)
  • 2021-02-07 09:37

    Select the UIButton in storyboard, check the installed as the bottom left in the image below.

    0 讨论(0)
  • 2021-02-07 09:39

    Check to make sure that the cell is not hidden. Add this code below

        cell.isHidden = false
    
    0 讨论(0)
提交回复
热议问题