Search code examples
iphoneiosobjective-cipad

adding to UICollectionViewCell contentView via nib


Is there a way to add subviews of a UICollectionViewCell to a contentView via xib? Because I think this is the right way to do so right? I think when I drag and drop UI via xib then it is dropped into the view instead of the contentView


Solution

  • When you drag and drop any Views into UICollectionViewCell XIB, you're dragging to cell.contentView, not cell.view.

    Please check in didSelect, you will see all subviews

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