Adding to UICollectionViewCell contentView via nib

Is there any way to add subviews from UICollectionViewCell to contentView via xib? Because I think this is the right way to do it right? I think when I drag the UI through xib, it is dropped into the view instead of the contentView

+3
source share
2 answers

When you drag any views into the UICollectionViewCell XIB, you drag the cell.contentView element, not the cell.view.

Please check in didSelect, you will see all the subheadings

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCell *cell = (MyCell*)[collectionView cellForItemAtIndexPath:indexPath];
    NSArray *views = [cell.contentView subviews];
    NSLog(@"Select %@",views);
}
-1
source

You can do this in the same way as you do to populate a TableViewCell via nib.

  • Create thread
  • Collectionview

    UINib * cellNib = [UINib nibWithNibName: @ "ECVCell": [NSBundle mainBundle]];   [self.collectionView registerNib: cellNib forCellWithReuseIdentifier: @ "ECVCell" ];

  • viewWithTag:, cellForItemAtIndexPath

:)

0

Source: https://habr.com/ru/post/1623193/


All Articles