UIImageView returning nil in a custom UICollectionViewCell

前端 未结 3 1352
面向向阳花
面向向阳花 2021-01-22 19:27

I asked a similar question last week but I think I have it narrowed down to more specifically what is going wrong. The custom cell is being loaded and looks to be called correct

3条回答
  •  醉梦人生
    2021-01-22 19:45

    The problem was not at all with the UIImageView. Rdelmar was correct in his statement of checking that the outlets were correct. The outlet reference to menuCollectionView was not linked properly and this was causing the error to pop up. By fixing the @IBOutlet connection and setting the delegate and dataSource via code rather than messing with the Storyboard, it cleared up the problem immediately. The code I used to set the delegate and dataSource are as follows and solely depend on the connection being a proper connection.

    self.menuCollectionView.delegate = self
    self.menuCollectionView.dataSource = self
    

    Simple fix really. I hope this can help someone else if they run into a similar problem! Check the connections first!!! Then go through and make sure everything is doing what it should!

提交回复
热议问题