UICollectionView doesn't contain UICollectionViewCell in IB

前端 未结 4 621
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 19:01

I\'m trying to add a UICollectionView to a .nib file in IB. I\'ve worked through a few tutorials and had no problems.

In my existing app, when I drag a collection vi

4条回答
  •  不知归路
    2020-12-18 19:23

    Define your cell view in a separate nib file. The view must be of type UICollectionViewCell or a subclass.

    Then, you must register the nib with your collection view:

    - (void)viewDidLoad
    {
        UINib *cellNib = [UINib nibWithNibName:@"MyNib" bundle:nil];
        [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cell"];
    }
    

提交回复
热议问题