UICollectionView cell.ViewWithTag returning nil for UILabel

后端 未结 2 984
予麋鹿
予麋鹿 2021-01-25 17:49

This label seems to return nil, even though I have the reuseIdentifier and tag set properly.

override func collectionView(collectionView: UICollectionView, cell         


        
相关标签:
2条回答
  • 2021-01-25 18:12

    Try removing this line from viewDidLoad:

    self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
    
    0 讨论(0)
  • 2021-01-25 18:30

    I have just created a sample project with your code and for me it works. Although you shouldn't force unwrap.

    Make sure you have the correct setup in your storyboard:

    Check if your collectionViewCell is setup correctly:

    And set the tag of your label:

    Here is the sample project

    0 讨论(0)
提交回复
热议问题