UIImageView in custom UICollectionViewCell returning nil all the time

后端 未结 5 1808
既然无缘
既然无缘 2020-12-29 05:02

OK in my story board I have made a UICollectionView with 3 cells. One of the cells I made a custom class for that obviously extends the UICollectionViewCell:

5条回答
  •  生来不讨喜
    2020-12-29 05:17

    Well, this is odd. I know a solution, but I don't quite understand why it makes a difference. I had the same exact setup and the same problem. The IBOutlet was getting set to nil for the UIImageView, but not the UILabels.

    Change your declaration for the UIImageView to be a strong property instead of an instance variable.

    @property (strong) IBOutlet UIImageView* imageView;
    

    This solved the issue for me. Clearly there is something with the way that UIImageView is connected / instantiated from the storyboard. As an added 'weird' factor, I use the same setup of ivars with a UITableViewCell and have no issue, only in the UICollectionViewCell

提交回复
热议问题